当前位置: PyQt5> Qt Designer安装及使用教程> Qt Designer UI文件的正确使用方法

Qt Designer UI文件的正确使用方法

2021年4月23日 01:42 743浏览 PyQt5中文网 Qt Designer安装及使用教程

Qt Designer UI文件的正确使用方法

from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(678, 413)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(Form.sizePolicy().hasHeightForWidth())
        Form.setSizePolicy(sizePolicy)
        Form.setMaximumSize(QtCore.QSize(16777215, 16777215))
        self.widget = QtWidgets.QWidget(Form)
        self.widget.setGeometry(QtCore.QRect(180, 120, 281, 141))
        self.widget.setObjectName("widget")
        self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.widget)
        self.verticalLayout_2.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout_2.setObjectName("verticalLayout_2")
        self.gridLayout = QtWidgets.QGridLayout()
        self.gridLayout.setObjectName("gridLayout")
        self.lineEdit_2 = QtWidgets.QLineEdit(self.widget)
        self.lineEdit_2.setEchoMode(QtWidgets.QLineEdit.Password)
        self.lineEdit_2.setObjectName("lineEdit_2")
        self.gridLayout.addWidget(self.lineEdit_2, 1, 2, 1, 1)
        self.label_2 = QtWidgets.QLabel(self.widget)
        self.label_2.setObjectName("label_2")
        self.gridLayout.addWidget(self.label_2, 1, 0, 1, 1)
        self.lineEdit = QtWidgets.QLineEdit(self.widget)
        self.lineEdit.setObjectName("lineEdit")
        self.gridLayout.addWidget(self.lineEdit, 0, 2, 1, 1)
        self.label = QtWidgets.QLabel(self.widget)
        self.label.setObjectName("label")
        self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
        self.verticalLayout_2.addLayout(self.gridLayout)
        self.Btn = QtWidgets.QPushButton(self.widget)
        self.Btn.setMinimumSize(QtCore.QSize(20, 20))
        self.Btn.setMaximumSize(QtCore.QSize(20000, 30))
        self.Btn.setStyleSheet("background-color: rgb(255, 170, 0);")
        self.Btn.setFlat(False)
        self.Btn.setObjectName("Btn")
        self.verticalLayout_2.addWidget(self.Btn)
        self.Btn.raise_()

        self.retranslateUi(Form)
        self.Btn.clicked.connect(Form.slot1)
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "Form"))
        self.label_2.setText(_translate("Form", "密码:"))
        self.label.setText(_translate("Form", "手机号:"))
        self.Btn.setToolTip(_translate("Form", "<html><head/><body><p>sss</p></body></html>"))
        self.Btn.setText(_translate("Form", "按钮"))


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    Form = QtWidgets.QWidget()
    ui = Ui_Form()
    ui.setupUi(Form)
    Form.show()
    sys.exit(app.exec_())
################################
# PyQt5中文网 - PyQt5全套视频教程 #
#    https://www.PyQt5.cn/     #
#         主讲: 村长            #
################################

from PyQt5.Qt import *
import sys

from test2 import Ui_Form

class Window(QWidget, Ui_Form):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("UI文件使用 - PyQt5中文网")
        self.resize(600, 500)
        self.func_list()
        self.setupUi(self)

    def slot1(self):
        print('QQQQQ')

    def func_list(self):
        self.func()

    def func(self):
        pass




if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = Window()
    window.show()
    sys.exit(app.exec_())


标签栏目

炫酷界面