Page 1 of 1

wxrichtextctrl and disappearing cursor

Posted: Fri Feb 15, 2019 1:28 pm
by refaelsh
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?

Re: wxrichtextctrl and disappearing cursor

Posted: Fri Feb 15, 2019 3:30 pm
by ONEEYEMAN
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.

Re: wxrichtextctrl and disappearing cursor

Posted: Sat Feb 16, 2019 7:16 pm
by refaelsh
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!
	});

Re: wxrichtextctrl and disappearing cursor

Posted: Sat Feb 16, 2019 11:00 pm
by doublemax
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

Re: wxrichtextctrl and disappearing cursor

Posted: Sat Feb 16, 2019 11:32 pm
by ONEEYEMAN
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.

Re: wxrichtextctrl and disappearing cursor

Posted: Sun Feb 17, 2019 8:35 pm
by refaelsh
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.

Re: wxrichtextctrl and disappearing cursor

Posted: Sun Feb 17, 2019 8:36 pm
by refaelsh
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.
:-)

Re: wxrichtextctrl and disappearing cursor

Posted: Sun Feb 17, 2019 8:37 pm
by refaelsh
doublemax, can you please explain to me why your solution works?

Re: wxrichtextctrl and disappearing cursor

Posted: Sun Feb 17, 2019 9:10 pm
by doublemax
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.