Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyQt4 : How can i toggle the "Stay On Top" behavior?

I want to create an app, where the user will decide it the main window will stay always on top of the other apps.

In PyQt4 it is easy to create a window that will stay always on top. This is covered here : PyQt: Always on top

What I want to have a widget (menu item, checkbox etc) that will toggle this behavior on or off. So far i haven't found a way to reset the original behavior.

thank you

UPDATE After the suggestion of İsmail 'cartman' Dönmez, I searched a bit more and I found an implementation of the WindowFlags example in PyQt4.

It can be found here

like image 521
pmav99 Avatar asked Jan 31 '11 11:01

pmav99


2 Answers

This should disable it:

window.setWindowFlags(window.windowFlags() & ~QtCore.Qt.WindowStaysOnTopHint)

This should enable it:

window.setWindowFlags(window.windowFlags() | QtCore.Qt.WindowStaysOnTopHint)
like image 115
Rosh Oxymoron Avatar answered Nov 16 '22 21:11

Rosh Oxymoron


Rosh is correct. But don't forget to include window.show() after you change the flag. Your window will be hidden when the flag is changed. I have also included the code for toggling the flag.

This will clear it:

window.setWindowFlags(window.windowFlags() & ~QtCore.Qt.WindowStaysOnTopHint)

This will enable it:

window.setWindowFlags(window.windowFlags() | QtCore.Qt.WindowStaysOnTopHint)

This will toggle it:

window.setWindowFlags(window.windowFlags() ^ QtCore.Qt.WindowStaysOnTopHint)

like image 5
Chad Avatar answered Nov 16 '22 21:11

Chad