pyqtpyqt4x11ubuntu-15.04

Ubuntu ignores PyQt4 flags


I wanna have a CustomDialog, which'll have minimize button and close button (no maximize)
So, what I do

from PyQt4 import QtGui

class CustomDialog(QtGui.QDialog):

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

In Windows It works as expected - in title bar go minimize button, then disabled maximize button and then close button
In Ubuntu I see no changes at all - close button next to maximize button. No minimize - CustomDialog behaves like it still is QDialog.
I don't know If it's Ubuntu "bug" or "PyQt" - for now I'm just confused.


Solution

  • From the 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.

    So it is likely the fault of your windows manager in ubuntu.

    Note that you might want to try updating the existing window flags, just to ensure you haven't overridden an important default (your current method of setting the window flags just sets the ones specified). You can instead do this to preserve the default window flags, but modify the ones you care about:

    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)
    

    Note that flags &= ~flag removes a flag. flags |= flag adds a flag.