Give focus back to the edit window sketcher.

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
paddle
Veteran
Posts: 1395
Joined: Mon Feb 03, 2020 4:47 pm

Re: Give focus back to the edit window sketcher.

Post by paddle »

openBrain wrote: Thu Jan 27, 2022 3:44 pm
paddle wrote: Thu Jan 27, 2022 3:18 pm Not sure what this means.
Something like :

Code: Select all

QMdiArea *mdi = qobject_cast<QMdiArea *>( Gui::MainWindow::getInstance()->centralWidget()->activeSubWindow());
if (!mdi) return;
mdi->activeSubWindow()->widget()->setFocus();
But maybe I'm not asking the correct question actually.
What I need is to give the keyboard events back to ViewProviderSketch. I'm not sure that what I need is to give focus to the main window. What do you think?
This is purpose of setFocus(). I tested above method in Python (no need to cast :D) and works.
I can't get it to work I still have the activeSubWindow error.

However I tested and found that the

Code: Select all

    Gui::MDIView* mdi = Gui::Application::Instance->activeDocument()->getActiveMainView();
    mdi->setFocus();
Prints the same pointer value if it's called from the ViewProviderSketch::activateHandler or if it's called from my widget. So I guess the focus should be set on the correct place.

Yet even if I don't use the space key to change constraint mode, once the focus is given back to that mdi, the space key goes nuts and does the sketch visibility on/off.
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Give focus back to the edit window sketcher.

Post by openBrain »

paddle wrote: Thu Jan 27, 2022 4:02 pm I can't get it to work I still have the activeSubWindow error.
Yet. There was a mistake in my previous post. Fixed this now (hopefully).

PS : and yes, key event propagation in FC is a bit cumbersome, and you may expect some hard time trying to deal with that. ;)
User avatar
paddle
Veteran
Posts: 1395
Joined: Mon Feb 03, 2020 4:47 pm

Re: Give focus back to the edit window sketcher.

Post by paddle »

openBrain wrote: Thu Jan 27, 2022 4:05 pm
paddle wrote: Thu Jan 27, 2022 4:02 pm I can't get it to work I still have the activeSubWindow error.
Yet. There was a mistake in my previous post. Fixed this now (hopefully).

PS : and yes, key event propagation in FC is a bit cumbersome, and you may expect some hard time trying to deal with that. ;)
I tried it but

Code: Select all

mdi->activeSubWindow()->widget()->setFocus()
Is still not OK. It gives a gui::MDIView has no member activeSubWindow.
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Give focus back to the edit window sketcher.

Post by openBrain »

paddle wrote: Thu Jan 27, 2022 8:48 pm Is still not OK. It gives a gui::MDIView has no member activeSubWindow.
Did you included <QMdiSubWindow> ?
User avatar
paddle
Veteran
Posts: 1395
Joined: Mon Feb 03, 2020 4:47 pm

Re: Give focus back to the edit window sketcher.

Post by paddle »

openBrain wrote: Fri Jan 28, 2022 8:36 am Did you included <QMdiSubWindow> ?
No and this morning it's working even without this include.

But the situation is the same.

It feels like my widget eventfilter triggers the comboview eventfilter. Because before I used onkeypressed reinmplementation in my widget and I didn't noticed that behavior. Though maybe it was here and I just didn't noticed it. I should rebuild this and see.
Post Reply