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

后端 未结 4 1559
遥遥无期
遥遥无期 2021-02-10 07:29

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 a

相关标签:
4条回答
  • 2021-02-10 08:01

    I'm not able to comment on Rosh's answer, so noting here - for PyQt 5.7 on Devuan, if you toggle the WindowStaysOnTopHint flag on a QDialog after it is shown, the window disappears and you need to show() it again immediately after. Other than this it works.

    0 讨论(0)
  • 2021-02-10 08:05

    You want the Qt::WindowStaysOnTopHint hint, see Window Flags Example.

    0 讨论(0)
  • 2021-02-10 08:09

    This should disable it:

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

    This should enable it:

    window.setWindowFlags(window.windowFlags() | QtCore.Qt.WindowStaysOnTopHint)
    
    0 讨论(0)
  • 2021-02-10 08:14

    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)

    0 讨论(0)
提交回复
热议问题