如何在PyQt5中为对话框添加最小化和最大化图标?

时间:2019-07-10 06:28:30

标签: python pyqt pyqt5

我是PyQt5的初学者。我已经在对话框中开发了一些应用程序,但后来我发现默认情况下对话框中没有最小化和最大化图标。如何在对话框中获取这些图标。 任何建议都会有所帮助。谢谢。

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'makebeautiful.ui'
#
# Created by: PyQt5 UI code generator 5.12
#
# WARNING! All changes made in this file will be lost!

from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_ZValue(object):
    def setupUi(self, ZValue):
        ZValue.setObjectName("ZValue")
        ZValue.resize(400, 300)
        self.lineEdit = QtWidgets.QLineEdit(ZValue)
        self.lineEdit.setGeometry(QtCore.QRect(130, 70, 131, 41))
        self.lineEdit.setObjectName("lineEdit")
        self.pushButton = QtWidgets.QPushButton(ZValue)
        self.pushButton.setGeometry(QtCore.QRect(130, 150, 131, 41))
        self.pushButton.setObjectName("pushButton")

        self.retranslateUi(ZValue)
        QtCore.QMetaObject.connectSlotsByName(ZValue)

    def retranslateUi(self, ZValue):
        _translate = QtCore.QCoreApplication.translate
        ZValue.setWindowTitle(_translate("ZValue", "Copy Z Cordinate"))
        self.pushButton.setText(_translate("ZValue", "Cofirm"))



import sys
from PyQt5.QtWidgets import QDialog,QApplication
from  makebeautiful import *
class MyForm(QDialog):
    def __init__(self):
        super().__init__()
        self.ui=Ui_ZValue()
        # self.ui.setWindowFlag(Qt.WindowMinimizeButtonHint, True)
        # self.ui.setWindowFlag(Qt.WindowMaximizeButtonHint, True)
        self.ui.setupUi(self)
        self.ui.pushButton.clicked.connect(self.dispmessage)
        self.show()
    def dispmessage(self):
        self.ui.lineEdit.setText("Clicked")
if __name__=="__main__":
    app=QApplication(sys.argv)
    w=MyForm()
    w.show()
    sys.exit(app.exec_())

1 个答案:

答案 0 :(得分:1)

要获得QDialog的最大化和最小化按钮,您需要分别设置窗口标记Qt.WindowMaximizeButtonHintQt.WindowMinimizeButtonHint,例如

dialog.setWindowFlag(Qt.WindowMinimizeButtonHint, True)
dialog.setWindowFlag(Qt.WindowMaximizeButtonHint, True)