Qt Designer生成的ui 代码
policy.py
# Form implementation generated from reading ui file 'policy.ui'
#
# Created by: PyQt6 UI code generator 6.4.2
#
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt6 import QtCore, QtGui, QtWidgets
class Ui_DialogPolicy(object):
def setupUi(self, DialogPolicy):
DialogPolicy.setObjectName("DialogPolicy")
DialogPolicy.resize(721, 557)
DialogPolicy.setSizeGripEnabled(False)
self.gridLayout = QtWidgets.QGridLayout(DialogPolicy)
self.gridLayout.setObjectName("gridLayout")
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.pushButton_config = QtWidgets.QPushButton(parent=DialogPolicy)
self.pushButton_config.setObjectName("pushButton_config")
self.horizontalLayout.addWidget(self.pushButton_config)
self.pushButton_init = QtWidgets.QPushButton(parent=DialogPolicy)
self.pushButton_init.setObjectName("pushButton_init")
self.horizontalLayout.addWidget(self.pushButton_init)
spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum)
self.horizontalLayout.addItem(spacerItem)
self.comboBox_policyType = QtWidgets.QComboBox(parent=DialogPolicy)
self.comboBox_policyType.setObjectName("comboBox_policyType")
self.comboBox_policyType.addItem("")
self.comboBox_policyType.addItem("")
self.horizontalLayout.addWidget(self.comboBox_policyType)
self.pushButton_syncAssignPolicy = QtWidgets.QPushButton(parent=DialogPolicy)
self.pushButton_syncAssignPolicy.setObjectName("pushButton_syncAssignPolicy")
self.horizontalLayout.addWidget(self.pushButton_syncAssignPolicy)
self.pushButton_syncAllPolicy = QtWidgets.QPushButton(parent=DialogPolicy)
self.pushButton_syncAllPolicy.setObjectName("pushButton_syncAllPolicy")
self.horizontalLayout.addWidget(self.pushButton_syncAllPolicy)
self.gridLayout.addLayout(self.horizontalLayout, 0, 0, 1, 1)
self.verticalLayout = QtWidgets.QVBoxLayout()
self.verticalLayout.setObjectName("verticalLayout")
self.label_policy = QtWidgets.QLabel(parent=DialogPolicy)
self.label_policy.setObjectName("label_policy")
self.verticalLayout.addWidget(self.label_policy)
self.listView_policyList = QtWidgets.QListView(parent=DialogPolicy)
self.listView_policyList.setObjectName("listView_policyList")
self.verticalLayout.addWidget(self.listView_policyList)
self.label_log = QtWidgets.QLabel(parent=DialogPolicy)
self.label_log.setObjectName("label_log")
self.verticalLayout.addWidget(self.label_log)
self.textEdit_log = QtWidgets.QTextEdit(parent=DialogPolicy)
self.textEdit_log.setObjectName("textEdit_log")
self.verticalLayout.addWidget(self.textEdit_log)
self.gridLayout.addLayout(self.verticalLayout, 1, 0, 1, 1)
self.retranslateUi(DialogPolicy)
QtCore.QMetaObject.connectSlotsByName(DialogPolicy)
def retranslateUi(self, DialogPolicy):
_translate = QtCore.QCoreApplication.translate
DialogPolicy.setWindowTitle(_translate("DialogPolicy", "Dialog"))
self.pushButton_config.setText(_translate("DialogPolicy", "服务器配置"))
self.pushButton_init.setText(_translate("DialogPolicy", "初始化"))
self.comboBox_policyType.setCurrentText(_translate("DialogPolicy", "DLP策略"))
self.comboBox_policyType.setItemText(0, _translate("DialogPolicy", "DLP策略"))
self.comboBox_policyType.setItemText(1, _translate("DialogPolicy", "ASEG策略"))
self.pushButton_syncAssignPolicy.setText(_translate("DialogPolicy", "同步指定策略"))
self.pushButton_syncAllPolicy.setText(_translate("DialogPolicy", "同步全部策略"))
self.label_policy.setText(_translate("DialogPolicy", "策略"))
self.label_log.setText(_translate("DialogPolicy", "日志"))
config.py
# Form implementation generated from reading ui file 'config.ui'
#
# Created by: PyQt6 UI code generator 6.4.2
#
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt6 import QtCore, QtGui, QtWidgets
class Ui_DialogConfig(object):
def setupUi(self, DialogConfig):
DialogConfig.setObjectName("DialogConfig")
DialogConfig.resize(584, 300)
DialogConfig.setMinimumSize(QtCore.QSize(500, 300))
DialogConfig.setMaximumSize(QtCore.QSize(1000, 500))
self.horizontalLayout_3 = QtWidgets.QHBoxLayout(DialogConfig)
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.SourcegroupBox = QtWidgets.QGroupBox(parent=DialogConfig)
self.SourcegroupBox.setObjectName("SourcegroupBox")
self.horizontalLayout = QtWidgets.QHBoxLayout(self.SourcegroupBox)
self.horizontalLayout.setObjectName("horizontalLayout")
self.formLayout = QtWidgets.QFormLayout()
self.formLayout.setObjectName("formLayout")
self.SourceIPLabel = QtWidgets.QLabel(parent=self.SourcegroupBox)
self.SourceIPLabel.setObjectName("SourceIPLabel")
self.formLayout.setWidget(0, QtWidgets.QFormLayout.ItemRole.LabelRole, self.SourceIPLabel)
self.SourceIPLineEdit = QtWidgets.QLineEdit(parent=self.SourcegroupBox)
self.SourceIPLineEdit.setObjectName("SourceIPLineEdit")
self.formLayout.setWidget(0, QtWidgets.QFormLayout.ItemRole.FieldRole, self.SourceIPLineEdit)
self.SourceSSHPortLabel = QtWidgets.QLabel(parent=self.SourcegroupBox)
self.SourceSSHPortLabel.setObjectName("SourceSSHPortLabel")
self.formLayout.setWidget(1, QtWidgets.QFormLayout.ItemRole.LabelRole, self.SourceSSHPortLabel)
self.SourceSSHPortLineEdit = QtWidgets.QLineEdit(parent=self.SourcegroupBox)
self.SourceSSHPortLineEdit.setObjectName("SourceSSHPortLineEdit")
self.formLayout.setWidget(1, QtWidgets.QFormLayout.ItemRole.FieldRole, self.SourceSSHPortLineEdit)
self.SourceSSHUserLabel = QtWidgets.QLabel(parent=self.SourcegroupBox)
self.SourceSSHUserLabel.setObjectName("SourceSSHUserLabel")
self.formLayout.setWidget(2, QtWidgets.QFormLayout.ItemRole.LabelRole, self.SourceSSHUserLabel)
self.SourceSSHUserLineEdit = QtWidgets.QLineEdit(parent=self.SourcegroupBox)
self.SourceSSHUserLineEdit.setObjectName("SourceSSHUserLineEdit")
self.formLayout.setWidget(2, QtWidgets.QFormLayout.ItemRole.FieldRole, self.SourceSSHUserLineEdit)
self.SourceSSHPwdLabel = QtWidgets.QLabel(parent=self.SourcegroupBox)
self.SourceSSHPwdLabel.setObjectName("SourceSSHPwdLabel")
self.formLayout.setWidget(3, QtWidgets.QFormLayout.ItemRole.LabelRole, self.SourceSSHPwdLabel)
self.SourceSSHPwdLineEdit = QtWidgets.QLineEdit(parent=self.SourcegroupBox)
self.SourceSSHPwdLineEdit.setObjectName("SourceSSHPwdLineEdit")
self.formLayout.setWidget(3, QtWidgets.QFormLayout.ItemRole.FieldRole, self.SourceSSHPwdLineEdit)
self.SourceJavaPortLabel = QtWidgets.QLabel(parent=self.SourcegroupBox)
self.SourceJavaPortLabel.setObjectName("SourceJavaPortLabel")
self.formLayout.setWidget(4, QtWidgets.QFormLayout.ItemRole.LabelRole, self.SourceJavaPortLabel)
self.SourceJavaPortLineEdit = QtWidgets.QLineEdit(parent=self.SourcegroupBox)
self.SourceJavaPortLineEdit.setObjectName("SourceJavaPortLineEdit")
self.formLayout.setWidget(4, QtWidgets.QFormLayout.ItemRole.FieldRole, self.SourceJavaPortLineEdit)
self.SourcePostgresIPLabel = QtWidgets.QLabel(parent=self.SourcegroupBox)
self.SourcePostgresIPLabel.setObjectName("SourcePostgresIPLabel")
self.formLayout.setWidget(5, QtWidgets.QFormLayout.ItemRole.LabelRole, self.SourcePostgresIPLabel)
self.SourcePostgresIPLineEdit = QtWidgets.QLineEdit(parent=self.SourcegroupBox)
self.SourcePostgresIPLineEdit.setObjectName("SourcePostgresIPLineEdit")
self.formLayout.setWidget(5, QtWidgets.QFormLayout.ItemRole.FieldRole, self.SourcePostgresIPLineEdit)
self.SourcePostgresPortLabel = QtWidgets.QLabel(parent=self.SourcegroupBox)
self.SourcePostgresPortLabel.setObjectName("SourcePostgresPortLabel")
self.formLayout.setWidget(6, QtWidgets.QFormLayout.ItemRole.LabelRole, self.SourcePostgresPortLabel)
self.SourcePostgresPortLineEdit = QtWidgets.QLineEdit(parent=self.SourcegroupBox)
self.SourcePostgresPortLineEdit.setObjectName("SourcePostgresPortLineEdit")
self.formLayout.setWidget(6, QtWidgets.QFormLayout.ItemRole.FieldRole, self.SourcePostgresPortLineEdit)
self.SourcePostgresUserLabel = QtWidgets.QLabel(parent=self.SourcegroupBox)
self.SourcePostgresUserLabel.setObjectName("SourcePostgresUserLabel")
self.formLayout.setWidget(7, QtWidgets.QFormLayout.ItemRole.LabelRole, self.SourcePostgresUserLabel)
self.SourcePostgresUserLineEdit = QtWidgets.QLineEdit(parent=self.SourcegroupBox)
self.SourcePostgresUserLineEdit.setObjectName("SourcePostgresUserLineEdit")
self.formLayout.setWidget(7, QtWidgets.QFormLayout.ItemRole.FieldRole, self.SourcePostgresUserLineEdit)
self.SourcePostgresPwdLabel = QtWidgets.QLabel(parent=self.SourcegroupBox)
self.SourcePostgresPwdLabel.setObjectName("SourcePostgresPwdLabel")
self.formLayout.setWidget(8, QtWidgets.QFormLayout.ItemRole.LabelRole, self.SourcePostgresPwdLabel)
self.SourcePostgresPwdLineEdit = QtWidgets.QLineEdit(parent=self.SourcegroupBox)
self.SourcePostgresPwdLineEdit.setObjectName("SourcePostgresPwdLineEdit")
self.formLayout.setWidget(8, QtWidgets.QFormLayout.ItemRole.FieldRole, self.SourcePostgresPwdLineEdit)
self.horizontalLayout.addLayout(self.formLayout)
self.horizontalLayout_3.addWidget(self.SourcegroupBox)
self.TargetgroupBox = QtWidgets.QGroupBox(parent=DialogConfig)
self.TargetgroupBox.setObjectName("TargetgroupBox")
self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.TargetgroupBox)
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.formLayout_2 = QtWidgets.QFormLayout()
self.formLayout_2.setObjectName("formLayout_2")
self.TargetIPLabel = QtWidgets.QLabel(parent=self.TargetgroupBox)
self.TargetIPLabel.setObjectName("TargetIPLabel")
self.formLayout_2.setWidget(0, QtWidgets.QFormLayout.ItemRole.LabelRole, self.TargetIPLabel)
self.TargetIPLineEdit = QtWidgets.QLineEdit(parent=self.TargetgroupBox)
self.TargetIPLineEdit.setObjectName("TargetIPLineEdit")
self.formLayout_2.setWidget(0, QtWidgets.QFormLayout.ItemRole.FieldRole, self.TargetIPLineEdit)
self.TargetSSHPortLabel = QtWidgets.QLabel(parent=self.TargetgroupBox)
self.TargetSSHPortLabel.setObjectName("TargetSSHPortLabel")
self.formLayout_2.setWidget(1, QtWidgets.QFormLayout.ItemRole.LabelRole, self.TargetSSHPortLabel)
self.TargetSSHPortLineEdit = QtWidgets.QLineEdit(parent=self.TargetgroupBox)
self.TargetSSHPortLineEdit.setObjectName("TargetSSHPortLineEdit")
self.formLayout_2.setWidget(1, QtWidgets.QFormLayout.ItemRole.FieldRole, self.TargetSSHPortLineEdit)
self.TargetSSHUserLabel = QtWidgets.QLabel(parent=self.TargetgroupBox)
self.TargetSSHUserLabel.setObjectName("TargetSSHUserLabel")
self.formLayout_2.setWidget(2, QtWidgets.QFormLayout.ItemRole.LabelRole, self.TargetSSHUserLabel)
self.TargetSSHUserLineEdit = QtWidgets.QLineEdit(parent=self.TargetgroupBox)
self.TargetSSHUserLineEdit.setObjectName("TargetSSHUserLineEdit")
self.formLayout_2.setWidget(2, QtWidgets.QFormLayout.ItemRole.FieldRole, self.TargetSSHUserLineEdit)
self.TargetSSHPwdLabel = QtWidgets.QLabel(parent=self.TargetgroupBox)
self.TargetSSHPwdLabel.setObjectName("TargetSSHPwdLabel")
self.formLayout_2.setWidget(3, QtWidgets.QFormLayout.ItemRole.LabelRole, self.TargetSSHPwdLabel)
self.TargetSSHPwdLineEdit = QtWidgets.QLineEdit(parent=self.TargetgroupBox)
self.TargetSSHPwdLineEdit.setObjectName("TargetSSHPwdLineEdit")
self.formLayout_2.setWidget(3, QtWidgets.QFormLayout.ItemRole.FieldRole, self.TargetSSHPwdLineEdit)
self.TargetJavaPortLabel = QtWidgets.QLabel(parent=self.TargetgroupBox)
self.TargetJavaPortLabel.setObjectName("TargetJavaPortLabel")
self.formLayout_2.setWidget(4, QtWidgets.QFormLayout.ItemRole.LabelRole, self.TargetJavaPortLabel)
self.TargetJavaPortLineEdit = QtWidgets.QLineEdit(parent=self.TargetgroupBox)
self.TargetJavaPortLineEdit.setObjectName("TargetJavaPortLineEdit")
self.formLayout_2.setWidget(4, QtWidgets.QFormLayout.ItemRole.FieldRole, self.TargetJavaPortLineEdit)
self.TargetPostgresIPLabel = QtWidgets.QLabel(parent=self.TargetgroupBox)
self.TargetPostgresIPLabel.setObjectName("TargetPostgresIPLabel")
self.formLayout_2.setWidget(5, QtWidgets.QFormLayout.ItemRole.LabelRole, self.TargetPostgresIPLabel)
self.TargetPostgresIPLineEdit = QtWidgets.QLineEdit(parent=self.TargetgroupBox)
self.TargetPostgresIPLineEdit.setObjectName("TargetPostgresIPLineEdit")
self.formLayout_2.setWidget(5, QtWidgets.QFormLayout.ItemRole.FieldRole, self.TargetPostgresIPLineEdit)
self.TargetPostgresPortLabel = QtWidgets.QLabel(parent=self.TargetgroupBox)
self.TargetPostgresPortLabel.setObjectName("TargetPostgresPortLabel")
self.formLayout_2.setWidget(6, QtWidgets.QFormLayout.ItemRole.LabelRole, self.TargetPostgresPortLabel)
self.TargetPostgresPortLineEdit = QtWidgets.QLineEdit(parent=self.TargetgroupBox)
self.TargetPostgresPortLineEdit.setObjectName("TargetPostgresPortLineEdit")
self.formLayout_2.setWidget(6, QtWidgets.QFormLayout.ItemRole.FieldRole, self.TargetPostgresPortLineEdit)
self.TargetPostgresUserLabel = QtWidgets.QLabel(parent=self.TargetgroupBox)
self.TargetPostgresUserLabel.setObjectName("TargetPostgresUserLabel")
self.formLayout_2.setWidget(7, QtWidgets.QFormLayout.ItemRole.LabelRole, self.TargetPostgresUserLabel)
self.TargetPostgresUserLineEdit = QtWidgets.QLineEdit(parent=self.TargetgroupBox)
self.TargetPostgresUserLineEdit.setObjectName("TargetPostgresUserLineEdit")
self.formLayout_2.setWidget(7, QtWidgets.QFormLayout.ItemRole.FieldRole, self.TargetPostgresUserLineEdit)
self.TargetPostgresPwdLabel = QtWidgets.QLabel(parent=self.TargetgroupBox)
self.TargetPostgresPwdLabel.setObjectName("TargetPostgresPwdLabel")
self.formLayout_2.setWidget(8, QtWidgets.QFormLayout.ItemRole.LabelRole, self.TargetPostgresPwdLabel)
self.TargetPostgresPwdLineEdit = QtWidgets.QLineEdit(parent=self.TargetgroupBox)
self.TargetPostgresPwdLineEdit.setObjectName("TargetPostgresPwdLineEdit")
self.formLayout_2.setWidget(8, QtWidgets.QFormLayout.ItemRole.FieldRole, self.TargetPostgresPwdLineEdit)
self.horizontalLayout_2.addLayout(self.formLayout_2)
self.horizontalLayout_3.addWidget(self.TargetgroupBox)
self.retranslateUi(DialogConfig)
QtCore.QMetaObject.connectSlotsByName(DialogConfig)
def retranslateUi(self, DialogConfig):
_translate = QtCore.QCoreApplication.translate
DialogConfig.setWindowTitle(_translate("DialogConfig", "Dialog"))
self.SourcegroupBox.setTitle(_translate("DialogConfig", "源主机配置项"))
self.SourceIPLabel.setText(_translate("DialogConfig", "UCSS地址:"))
self.SourceSSHPortLabel.setText(_translate("DialogConfig", "SSH端口:"))
self.SourceSSHUserLabel.setText(_translate("DialogConfig", "SSH用户名:"))
self.SourceSSHPwdLabel.setText(_translate("DialogConfig", "SSH密码:"))
self.SourceJavaPortLabel.setText(_translate("DialogConfig", "Java服务端口:"))
self.SourcePostgresIPLabel.setText(_translate("DialogConfig", "PGSQL地址:"))
self.SourcePostgresPortLabel.setText(_translate("DialogConfig", "PGSQL端口:"))
self.SourcePostgresUserLabel.setText(_translate("DialogConfig", "PGSQL用户名:"))
self.SourcePostgresPwdLabel.setText(_translate("DialogConfig", "PGSQL密码:"))
self.TargetgroupBox.setTitle(_translate("DialogConfig", "目的主机配置项"))
self.TargetIPLabel.setText(_translate("DialogConfig", "UCSS地址:"))
self.TargetSSHPortLabel.setText(_translate("DialogConfig", "SSH端口:"))
self.TargetSSHUserLabel.setText(_translate("DialogConfig", "SSH用户名:"))
self.TargetSSHPwdLabel.setText(_translate("DialogConfig", "SSH密码:"))
self.TargetJavaPortLabel.setText(_translate("DialogConfig", "Java服务端口:"))
self.TargetPostgresIPLabel.setText(_translate("DialogConfig", "PGSQL地址::"))
self.TargetPostgresPortLabel.setText(_translate("DialogConfig", "PGSQL端口:"))
self.TargetPostgresUserLabel.setText(_translate("DialogConfig", "PGSQL用户名:"))
self.TargetPostgresPwdLabel.setText(_translate("DialogConfig", "PGSQL密码:"))
如何使用他?
main.py
# -*- coding: utf-8 -*-
"""
@Time : 2023/4/24 16:55
@FileName: main.py
"""
import sys
from PyQt6.QtWidgets import QApplication, QMainWindow, QDialog
from PyQt6.QtGui import QAction
from PyQt6.QtCore import pyqtSignal
from ui.policy import Ui_DialogPolicy
from ui.config import Ui_DialogConfig
class MainWindow(QDialog, Ui_DialogPolicy):
# 定义一个信号,用于在主界面中点击按钮时发射给弹出界面
showDialogSignal = pyqtSignal()
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.setupUi(self)
# 将按钮的clicked信号连接到槽函数
self.pushButton_config.clicked.connect(self.show_dialog)
def show_dialog(self):
# 发射信号给弹出界面
self.showDialogSignal.emit()
class DialogWindow(QDialog, Ui_DialogConfig):
def __init__(self, parent=None):
super(DialogWindow, self).__init__(parent)
self.setupUi(self)
def show_dialog(self):
# 显示弹出界面
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
app.setStyle('Fusion')
main_window = MainWindow()
dialog_window = DialogWindow()
# 将主界面的信号连接到弹出界面的槽函数
main_window.showDialogSignal.connect(dialog_window.show_dialog)
# 显示主界面
main_window.show()
app.exec()
标签:setObjectName,QFormLayout,Designer,界面,Qt,parent,self,QtWidgets,formLayout
From: https://www.cnblogs.com/hanfe1/p/17352452.html