wxrichtextctrl and disappearing cursor Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
refaelsh
Earned a small fee
Earned a small fee
Posts: 20
Joined: Tue Feb 05, 2019 7:25 pm

wxrichtextctrl and disappearing cursor

Post by refaelsh » Fri Feb 15, 2019 1:28 pm

In my GUI I have a wxSplitterWindow. The wxSplitterWindow contains 2 wxPanels: one has wxDataViewListCtrl and the other has wxRichTextCtrl.
I am programmatically updating the wxDataViewListCtrl with different data depending on some data base. I want the focus to be on the wxRichTextCtrl after every wxDataViewListCtrl update, e.g., I want the cursor to be blinking in the wxRichTextCtrl and ready for keyboard input (it simulates cmd.exe). I've tried things like `m_richText->SetFocus()` but it does not helps. Any ideas please?

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4356
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxrichtextctrl and disappearing cursor

Post by ONEEYEMAN » Fri Feb 15, 2019 3:30 pm

Hi,
1. What's your wx version?
2. What OS/toolkit?
3. Any special/non-standard option for building wx?
4. Are you using wxRichTextCtrl or wxTextCtrl with TE_RICH{2} style?
5. Can we see some code? Where did you put the SetFocus() call?

Thank you.

refaelsh
Earned a small fee
Earned a small fee
Posts: 20
Joined: Tue Feb 05, 2019 7:25 pm

Re: wxrichtextctrl and disappearing cursor

Post by refaelsh » Sat Feb 16, 2019 7:16 pm

1. I use version 3.1.2.
2. Windows 10.
3. I've build static libs using the default options (I've changed nothing).
4. wxRichTextCtrl.
5. Here is some code:

Code: Select all

	view_model->tree.subscribe([=](std::shared_ptr<std::vector<std::shared_ptr<Line>>> t)
	{
		// Do stuff here that updates the wxDataViewListCtrl with new data from a data base.
		
		// Then do this to return the focus to the wxRichTextCtrl.
		frame->m_richText->SetFocus(); // <-- This has no effect!
	});

User avatar
doublemax
Moderator
Moderator
Posts: 15064
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxrichtextctrl and disappearing cursor

Post by doublemax » Sat Feb 16, 2019 11:00 pm

Does the control properly get focus if you do it manually (click into the window)?

If yes, try calling SetFocus at a later time using wxEvtHandler::CallAfter():
https://docs.wxwidgets.org/trunk/classw ... 3b8a0c6a12
Use the source, Luke!

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4356
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxrichtextctrl and disappearing cursor

Post by ONEEYEMAN » Sat Feb 16, 2019 11:32 pm

Hi,
Also check if richtext sample works for you, i.e. the control can get focus and you can type in it after pressing the ALT+TAB.

Thank you.

refaelsh
Earned a small fee
Earned a small fee
Posts: 20
Joined: Tue Feb 05, 2019 7:25 pm

Re: wxrichtextctrl and disappearing cursor

Post by refaelsh » Sun Feb 17, 2019 8:35 pm

ONEEYEMAN wrote:Hi,
Also check if richtext sample works for you, i.e. the control can get focus and you can type in it after pressing the ALT+TAB.

Thank you.
The wxRichTextCtrl sample works perfectly, including ALT+TAB.

refaelsh
Earned a small fee
Earned a small fee
Posts: 20
Joined: Tue Feb 05, 2019 7:25 pm

Re: wxrichtextctrl and disappearing cursor

Post by refaelsh » Sun Feb 17, 2019 8:36 pm

doublemax wrote:Does the control properly get focus if you do it manually (click into the window)?

If yes, try calling SetFocus at a later time using wxEvtHandler::CallAfter():
https://docs.wxwidgets.org/trunk/classw ... 3b8a0c6a12
That solved the issue. Thanks a a lot everyone.
:-)
Last edited by refaelsh on Sun Feb 17, 2019 8:37 pm, edited 1 time in total.

refaelsh
Earned a small fee
Earned a small fee
Posts: 20
Joined: Tue Feb 05, 2019 7:25 pm

Re: wxrichtextctrl and disappearing cursor

Post by refaelsh » Sun Feb 17, 2019 8:37 pm

doublemax, can you please explain to me why your solution works?

User avatar
doublemax
Moderator
Moderator
Posts: 15064
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxrichtextctrl and disappearing cursor

Post by doublemax » Sun Feb 17, 2019 9:10 pm

refaelsh wrote:doublemax, can you please explain to me why your solution works?
It was just a guess :)

It all depends on when / from where you make the SetFocus() call. Usually it's from inside another event handler. And after your event handler is finished, there may be other events that are getting processed. And one of these could override your SetFocus() call by setting the focus to another control. By using CallAfter(), your code is only called after all other events have been processed.

But in order to find out who exactly overrides the focus, i'd need a working sample and analyze it.
Use the source, Luke!

Post Reply