Ubuntu 忽略 PyQt4 标志

Ubuntu ignores PyQt4 flags

我想要一个 CustomDialog,它有最小化按钮和关闭按钮(没有最大化)
所以,我做什么

from PyQt4 import QtGui

class CustomDialog(QtGui.QDialog):

    def __init__(self):
        super(WinDialog, self).__init__(None,
            QtCore.Qt.WindowMinimizeButtonHint |\
            QtCore.Qt.WindowCloseButtonHint|)

在 Windows 中按预期工作 - 在标题栏中转到最小化按钮,然后禁用最大化按钮,然后关闭按钮
在 Ubuntu 中,我完全看不到任何变化 - 最大化按钮旁边的关闭按钮。没有最小化 - CustomDialog 的行为就像它仍然是 QDialog。
我不知道是 Ubuntu "bug" 还是 "PyQt" - 现在我很困惑。

来自documentation

Note that the X11 version of Qt may not be able to deliver all combinations of style flags on all systems. This is because on X11, Qt can only ask the window manager, and the window manager can override the application's settings. On Windows, Qt can set whatever flags you want.

所以这很可能是您 windows 在 ubuntu 的经理的错。

请注意,您可能想尝试更新现有的 window 标志,以确保您没有覆盖重要的默认值(您当前设置 window 标志的方法只是设置那些指定的)。您可以改为这样做以保留默认的 window 标志,但修改您关心的标志:

def __init__(self):
    super(WinDialog, self).__init__(None)
    windowFlags = self.windowFlags()
    windowFlags &= ~Qt.WindowMaximizeButtonHint # remove maximise button
    windowFlags &= ~Qt.WindowMinMaxButtonsHint  # remove min/max combo
    windowFlags &= ~Qt.WindowContextHelpButtonHint # remove help button
    windowFlags |= Qt.WindowMinimizeButtonHint  # Add minimize  button
    self.setWindowFlags(windowFlags)

请注意,flags &= ~flag 删除了一个标志。 flags |= flag 添加一个标志。