Reputation: 583
I would like to know if it's possible to set my QMainWindow always on top .
I tried:
mainWindow.setWindowFlags(Qt::WindowStaysOnBottomHint);
mainWindow is a QMainWindow extended object. But it doesn't work and my window disapear.
Upvotes: 1
Views: 2488
Reputation: 6893
If you want to make a window as Dialog, there is another way. Just call setModal(true) or setWindowModality(), afterward show(). Unlike exec(), show() returns control to the caller instantaneously.It wont stuck as QDialog in exec().
i.e
setModel(true);//In Constructor
then while calling or invoking the new window,
MyWindow* myWindow = new MyWindow(this);
myWindow->show();
Upvotes: 0
Reputation: 2660
Yes, it is possible but there are two errors in your code:
Qt::WindowStaysOnBottomHint
which is set.Qt::WindowStaysOnBottomHint
flag (which represent the opposite of what you want) instead of Qt::WindowStaysOnTopHint
.A correct way of doing that is:
Qt::WindowFlags flags = mainWindow.windowFlags();
mainWindow.setWindowFlags(flags | Qt::WindowStaysOnTopHint);
Note that on some window managers on X11 you also have to pass Qt::X11BypassWindowManagerHint for this flag to work correctly.
In that case you should do:
Qt::WindowFlags flags = mainWindow.windowFlags();
mainWindow.setWindowFlags(flags | Qt::X11BypassWindowManagerHint | Qt::WindowStaysOnTopHint);
Upvotes: 3