PyQt: Dialog's Minimize Window Button is Missing in OSX

﹥>﹥吖頭↗ 提交于 2019-12-24 03:21:02

问题


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.


回答1:


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.




回答2:


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).



来源:https://stackoverflow.com/questions/22187207/pyqt-dialogs-minimize-window-button-is-missing-in-osx

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!