Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt correct way to show/display/raise window

Tags:

c++

qt

pyqt4

Quite often I find that I need to show and bring a window to a front. For example when the user attempts to reload the same document I simply bring up the old one. To do this I have code like this:

widget->raise();
widget->activateWindow();
widget->showNormal();

It's starting to feel like I'm missing a shortcut function. Surely this type of behaviour is quite common. Is there some preferred function that will do all of the above and/or just do the right thing on each target OS?


Note: I've just noticed a defect, thus a special function is even more important now. If the window is minimized, activateWindow does not work. This happens even if you reorder the above to showNormal first.

like image 731
edA-qa mort-ora-y Avatar asked Oct 19 '11 06:10

edA-qa mort-ora-y


1 Answers

this is a working "shortcut" :

widget->setWindowState(Qt::WindowActive) ;

You can couple it with the last Qt::WindowState of the window. This notation is not very explicit though.

like image 56
azf Avatar answered Oct 23 '22 18:10

azf