Solved Avoid that a QDialog activates with show()
-
Hello,
I have an application that is a main window, which can have several QDialogs as children (always in front). When I create and show such a child QDialog, it activates (i.e. it gets the mouse and keyboard focus/input, which is normal). However, I would prefer to have the QDialog not activate, since I still need the keyboard focus on the main window.
So what I am currently doing is:childDialog->show(); mainWindow->activateWindow();
But I feel this is not the correct way of doing. Is there a way to show a QDialog without having it activated automatically?
Thanks for any information -
There's an attribute for that. Somewhere before showing the dialog call
setAttribute(Qt::WA_ShowWithoutActivating)
on it. -
An option could be to add the Qt::WindowDoesNotAcceptFocus flags attributs of your dialog,
if your dialog doesn't have any line or text edit. -
Thanks for the quick reply. My Dialogs have actually those line widgets, etc. They are more like contextual tool window, that pop open if a certain object is selected in the main window. The User will very probably continue to work in the main window, but if he/she clicks on the child dialog, he/she can change the selected object's properties.
-
There's an attribute for that. Somewhere before showing the dialog call
setAttribute(Qt::WA_ShowWithoutActivating)
on it. -
That's just perfect! How could I oversee this?
Thanks a lot!