pyQt5 change MainWindow Flags

前端 未结 2 1815
梦谈多话
梦谈多话 2021-02-07 20:58

I use python 3.4 , pyQt5 and Qt designer (Winpython distribution). I like the idea of making guis by designer and importing them in python with setupUi. I\'m able to show MainWi

相关标签:
2条回答
  • 2021-02-07 21:26

    Every call of setWindowFlags will completely override the current settings, so you need to set all the flags at once. Also, you must include the CustomizeWindowHint flag, otherwise all the other hints will be ignored. The following will probably work on Windows:

        self.setWindowFlags(
            QtCore.Qt.Window |
            QtCore.Qt.CustomizeWindowHint |
            QtCore.Qt.WindowTitleHint |
            QtCore.Qt.WindowCloseButtonHint |
            QtCore.Qt.WindowStaysOnTopHint
            )
    

    However, it is highly unlikely this will work on all platforms. "Hint" really does mean just that. Window managers are completely free to ignore these flags and there's no guarantee they will all behave in the same way.

    PS:

    It is not possible to set the window flags in Qt Designer.

    0 讨论(0)
  • 2021-02-07 21:37

    I would propose a different solution, because it keeps the existing flags. Reason to do this, is to NOT mingle with UI-specific presets (like that a dialog has not by default a "maximize" or "minimize" button).

    self.setWindowFlags(self.windowFlags() # reuse initial flags
        & ~QtCore.Qt.WindowContextHelpButtonHint # negate the flag you want to unset
    )
    
    0 讨论(0)
提交回复
热议问题