Qt Designer运行界面:
MainWinSignalSlog02.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1032</width>
<height>212</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<property name="toolTip">
<string/>
</property>
<widget class="QGroupBox" name="groupBox">
<property name="geometry">
<rect>
<x>30</x>
<y>40</y>
<width>641</width>
<height>151</height>
</rect>
</property>
<property name="title">
<string>打印控制</string>
</property>
<widget class="QPushButton" name="pushButton_close">
<property name="geometry">
<rect>
<x>290</x>
<y>100</y>
<width>93</width>
<height>28</height>
</rect>
</property>
<property name="text">
<string>关闭</string>
</property>
</widget>
<widget class="Line" name="line">
<property name="geometry">
<rect>
<x>30</x>
<y>80</y>
<width>551</width>
<height>16</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
<widget class="Line" name="line_2">
<property name="geometry">
<rect>
<x>243</x>
<y>90</y>
<width>20</width>
<height>51</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
<widget class="QWidget" name="">
<property name="geometry">
<rect>
<x>30</x>
<y>30</y>
<width>551</width>
<height>30</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>打印份数:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="numberSpinBox"/>
</item>
<item>
<widget class="QComboBox" name="styleCombo">
<property name="currentIndex">
<number>1</number>
</property>
<item>
<property name="text">
<string>A3</string>
</property>
</item>
<item>
<property name="text">
<string>A4</string>
</property>
</item>
<item>
<property name="text">
<string>A5</string>
</property>
</item>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>纸张类型:</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="printButton">
<property name="text">
<string>打印</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="">
<property name="geometry">
<rect>
<x>30</x>
<y>100</y>
<width>189</width>
<height>30</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QCheckBox" name="previewStatus">
<property name="text">
<string>全屏预览</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="previewButton">
<property name="text">
<string>预览</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<widget class="QGroupBox" name="groupBox_op">
<property name="geometry">
<rect>
<x>700</x>
<y>40</y>
<width>311</width>
<height>151</height>
</rect>
</property>
<property name="title">
<string>操作结果</string>
</property>
<widget class="QLabel" name="resultLabel">
<property name="geometry">
<rect>
<x>20</x>
<y>30</y>
<width>271</width>
<height>101</height>
</rect>
</property>
<property name="text">
<string/>
</property>
</widget>
</widget>
</widget>
<resources/>
<connections>
<connection>
<sender>pushButton_close</sender>
<signal>clicked()</signal>
<receiver>Form</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel">
<x>113</x>
<y>228</y>
</hint>
<hint type="destinationlabel">
<x>100</x>
<y>303</y>
</hint>
</hints>
</connection>
</connections>
</ui>
Ui_MainWinSignalSlog02.py文章来源:https://www.toymoban.com/news/detail-617544.html
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'd:\project\python\pyqt5\designerDemo\MainWinSignalSlog02.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(1032, 212)
Form.setToolTip("")
self.groupBox = QtWidgets.QGroupBox(Form)
self.groupBox.setGeometry(QtCore.QRect(30, 40, 641, 151))
self.groupBox.setObjectName("groupBox")
self.pushButton_close = QtWidgets.QPushButton(self.groupBox)
self.pushButton_close.setGeometry(QtCore.QRect(290, 100, 93, 28))
self.pushButton_close.setObjectName("pushButton_close")
self.line = QtWidgets.QFrame(self.groupBox)
self.line.setGeometry(QtCore.QRect(30, 80, 551, 16))
self.line.setFrameShape(QtWidgets.QFrame.HLine)
self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line.setObjectName("line")
self.line_2 = QtWidgets.QFrame(self.groupBox)
self.line_2.setGeometry(QtCore.QRect(243, 90, 20, 51))
self.line_2.setFrameShape(QtWidgets.QFrame.VLine)
self.line_2.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line_2.setObjectName("line_2")
self.widget = QtWidgets.QWidget(self.groupBox)
self.widget.setGeometry(QtCore.QRect(30, 30, 551, 30))
self.widget.setObjectName("widget")
self.horizontalLayout = QtWidgets.QHBoxLayout(self.widget)
self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout.setObjectName("horizontalLayout")
self.label = QtWidgets.QLabel(self.widget)
self.label.setObjectName("label")
self.horizontalLayout.addWidget(self.label)
self.numberSpinBox = QtWidgets.QSpinBox(self.widget)
self.numberSpinBox.setObjectName("numberSpinBox")
self.horizontalLayout.addWidget(self.numberSpinBox)
self.styleCombo = QtWidgets.QComboBox(self.widget)
self.styleCombo.setObjectName("styleCombo")
self.styleCombo.addItem("")
self.styleCombo.addItem("")
self.styleCombo.addItem("")
self.horizontalLayout.addWidget(self.styleCombo)
spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem)
self.label_2 = QtWidgets.QLabel(self.widget)
self.label_2.setObjectName("label_2")
self.horizontalLayout.addWidget(self.label_2)
self.printButton = QtWidgets.QPushButton(self.widget)
self.printButton.setObjectName("printButton")
self.horizontalLayout.addWidget(self.printButton)
self.widget1 = QtWidgets.QWidget(self.groupBox)
self.widget1.setGeometry(QtCore.QRect(30, 100, 189, 30))
self.widget1.setObjectName("widget1")
self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.widget1)
self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.previewStatus = QtWidgets.QCheckBox(self.widget1)
self.previewStatus.setObjectName("previewStatus")
self.horizontalLayout_2.addWidget(self.previewStatus)
self.previewButton = QtWidgets.QPushButton(self.widget1)
self.previewButton.setObjectName("previewButton")
self.horizontalLayout_2.addWidget(self.previewButton)
self.groupBox_op = QtWidgets.QGroupBox(Form)
self.groupBox_op.setGeometry(QtCore.QRect(700, 40, 311, 151))
self.groupBox_op.setObjectName("groupBox_op")
self.resultLabel = QtWidgets.QLabel(self.groupBox_op)
self.resultLabel.setGeometry(QtCore.QRect(20, 30, 271, 101))
self.resultLabel.setText("")
self.resultLabel.setObjectName("resultLabel")
self.retranslateUi(Form)
self.styleCombo.setCurrentIndex(1)
self.pushButton_close.clicked.connect(Form.close)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.groupBox.setTitle(_translate("Form", "打印控制"))
self.pushButton_close.setText(_translate("Form", "关闭"))
self.label.setText(_translate("Form", "打印份数:"))
self.styleCombo.setItemText(0, _translate("Form", "A3"))
self.styleCombo.setItemText(1, _translate("Form", "A4"))
self.styleCombo.setItemText(2, _translate("Form", "A5"))
self.label_2.setText(_translate("Form", "纸张类型:"))
self.printButton.setText(_translate("Form", "打印"))
self.previewStatus.setText(_translate("Form", "全屏预览"))
self.previewButton.setText(_translate("Form", "预览"))
self.groupBox_op.setTitle(_translate("Form", "操作结果"))
CallMainWinSignalSlog02.py文章来源地址https://www.toymoban.com/news/detail-617544.html
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import pyqtSignal, Qt
from Ui_MainWinSignalSlog02 import Ui_Form
class MyMainWindow(QMainWindow, Ui_Form):
helpSignal = pyqtSignal(str)
printSignal = pyqtSignal(list)
# 声明一个多重载版本的信号,包括一个带int和str类型参数的信号,以及带str类型参数的信号
previewSignal = pyqtSignal([int, str], [str])
def __init__(self, parent=None):
super(MyMainWindow, self).__init__(parent)
self.setupUi(self)
self.initUI()
def initUI(self):
self.helpSignal.connect(self.showHelpMessage)
self.printSignal.connect(self.printPaper)
self.previewSignal[str].connect(self.previewPaper)
self.previewSignal[int, str].connect(self.previewPaperWithArgs)
self.printButton.clicked.connect(self.emitPrintSignal)
self.previewButton.clicked.connect(self.emitPrivewSignal)
# 发射预览信号
def emitPrivewSignal(self):
if self.previewStatus.isChecked() == True:
self.previewSignal[int, str].emit(1080, " Full Screen")
elif self.previewStatus.isChecked() == False:
self.previewSignal[str].emit("PreView")
pass
# 发射打印信号
def emitPrintSignal(self):
pList = []
pList.append(self.numberSpinBox.value())
pList.append(self.styleCombo.currentText())
self.printSignal.emit(pList)
def printPaper(self, list):
self.resultLabel.setText("打印:" + "份数:" + str(list[0]) + "纸张:" +str(list[1]))
def previewPaperWithArgs(self, style, text):
self.resultLabel.setText(str(style) + text)
def previewPaper(self, text):
self.resultLabel.setText(text)
# 重载按键事件
def keyPressEvent(self, event):
if event.key() == Qt.Key_F1:
self.helpSignal.emit("help message")
# 显示帮助信息
def showHelpMessage(self, message):
self.resultLabel.setText(message)
self.statusBar().showMessage(message)
if __name__ == "__main__":
app = QApplication(sys.argv)
win = MyMainWindow()
win.show()
sys.exit(app.exec_())
到了这里,关于PyQt5 Qt Designer使用(界面显示与业务逻辑分离模式)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!