PyQt:OSX 中缺少对话框的最小化窗口按钮 [英] PyQt: Dialog's Minimize Window Button is Missing in OSX
问题描述
使用以下方法创建的对话框:
A dialog created with:
class GUI(QtGui.QMainWindow):
def __init__(self):
super(GUI, self).__init__()
global dialog
dialog = QtGui.QDialog()
myGui = GUI()
缺少最小化窗口按钮 (OSX).它在 Windows 中.我是否必须设置一些标志来显示这个丢失的控制器?请指教,提前致谢!
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!
我没有尝试使用 QtGui.QDialog() 解决无最小化按钮的问题.但似乎我部分知道如何使用 QtGui.QMainWindow 获取丢失的按钮.这是说明基本语法的最简单代码:
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_())
QtGui.QMainWindow 背后的一个关键"概念"是我们首先声明 QWidget()
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)
不要忘记的最后一步是使用以下方法将此 QWidget() 分配给对话框本身:
Last step not to forget is to assign this QWidget() to dialog itself using:
self.setCentralWidget(myQWidget)
其中 'self' 是 QtGui.QMainWindow 的实例化子类.
where 'self' is an instanced subclass of QtGui.QMainWindow.
推荐答案
QtGui.QDialog
不提供任何平台上的最小化按钮,但 QtGui.QMainWindow
提供在每个平台(Windows、Linux 和 OSX)上.您正在创建一个 QDialog
对象,同时创建一个 GUI
对象,它是 QMainWindow
的子类.如果您编写 myGui.show()
,该窗口将为您提供所有三个按钮(最小化、最大化/恢复和关闭).但是在 dialog.show()
的情况下,你不会有两个(最小化和最大化/恢复).这是Qt的限制.
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.
这篇关于PyQt:OSX 中缺少对话框的最小化窗口按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!