PyQt: Dialog's Minimize Window Button is Missi

2019-08-08 16:19发布

A dialog created with:

class GUI(QtGui.QMainWindow):
    def __init__(self):
        super(GUI, self).__init__()

global dialog
dialog = QtGui.QDialog()
myGui = GUI()

is missing a minimize window button (OSX). It is there in Windows. Do I have to set some flag to display this missing controller? Please advise, Thanks in advance!

EDITED LATER:

I didn't try to solve a no-minimize-button issue with QtGui.QDialog(). But it appears I partically aware how to get that missing button using QtGui.QMainWindow. Here is the simplest code illustrating a basic syntax:

from PyQt4 import QtCore, QtGui

app = QtGui.QApplication(sys.argv)

class MainWindow(QtGui.QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()

        myQWidget = QtGui.QWidget()
        myBoxLayout = QtGui.QVBoxLayout()       

        myLineEdit = QtGui.QLineEdit("myLineEdit")
        myBoxLayout.addWidget(myLineEdit)

        myQWidget.setLayout(myBoxLayout)

        self.setCentralWidget(myQWidget)


window = MainWindow()
window.show()
window.resize(480,320)
sys.exit(app.exec_())

A 'key' 'concept' behind QtGui.QMainWindow is that first we declare QWidget()

myQWidget = QtGui.QWidget() 

to which we assign a 'main' layout:

myQWidget.setLayout(myBoxLayout)

Last step not to forget is to assign this QWidget() to dialog itself using:

self.setCentralWidget(myQWidget)

where 'self' is an instanced subclass of QtGui.QMainWindow.

2条回答
老娘就宠你
2楼-- · 2019-08-08 16:47

I can't test this myself, but you could try setting these window flags:

    dialog.setWindowFlags(dialog.windowFlags() |
        QtCore.Qt.WindowMinimizeButtonHint |
        QtCore.Qt.WindowSystemMenuHint)

(The WindowSystemMenuHint flag may not be necessary).

查看更多
疯言疯语
3楼-- · 2019-08-08 16:56

QtGui.QDialog does not offer a minimize button on any platform, but QtGui.QMainWindow does offer on each platform (Windows, Linux and OSX). You are creating a QDialog object and at the same time an object of GUI which is subclass of QMainWindow. If you write myGui.show() the window will offer you all three buttons (minimize, maximize/restore and close). But in case of dialog.show(), you will not have two of them (minimize and maximize/restore). It's Qt's limitation.

查看更多
登录 后发表回答