当前位置:网站首页>PyQt5快速开发与实战 3.4 信号与槽关联
PyQt5快速开发与实战 3.4 信号与槽关联
2022-07-26 16:28:00 【Ding Jiaxiong】
PyQt5快速开发与实战
3. 第3章 Qt Designer的使用
3.4 信号与槽关联
信号(signal)和槽(slot)是Qt的核心机制。在创建事件循环之后,通过建立信号和槽的连接就可以实现对象之间的通信。当信号发射(emit)时,连接的槽函数将会自动执行。在 PyQt 5中,信号和槽通过QObject.signal.connect()连接。
所有从 QObject类或其子类(如QWidget)派生的类都能够包含信号和槽。当对象改变其状态时,信号就由该对象发射出去。槽用于接收信号,但它们是普通的对象成员函数。多个信号可以与单个槽进行连接,单个信号也可以与多个槽进行连接。总之,信号和槽构建了一种强大的控件编程机制。
3.4.1 简单入门


这意味着对”关闭窗口“按钮单击后会发射clicked信号,这个信号会被Form窗体的槽函数close()捕捉,并触发该窗体的close行为。



新建调用窗口显示的文件CallMainWinSignalSlot01.py
import sys
from PyQt5.QtWidgets import QApplication,QMainWindow
from MainWinSignalSlog01 import Ui_Form
class MyMainWindow(QMainWindow , Ui_Form):
def __init__(self,parent = None):
super(MyMainWindow, self).__init__(parent)
self.setupUi(self)
if __name__ == '__main__':
from pyqt5_plugins.examples.exampleqmlitem import QtCore
QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
app = QApplication(sys.argv)
myWin = MyMainWindow()
myWin.show()
sys.exit(app.exec())

点击按钮,窗口关闭,程序退出。
3.4.2 快速进阶
利用“信号与槽编辑窗口”进行信号调整等操作。

使用一个复选框来控制一个标签的显示和一个文本edit的可用。


关键代码

Eric这个IDE有一个叫“生成对话框代码”的功能,也可以生成信号和槽。
边栏推荐
- VS2017打开项目提示需要迁移的解决方法
- ES:Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes
- C#转整型的三种方式的区别以及效率对比
- IDEA 阿里云多模块部署
- 利用MySQL主从复制延迟拯救误删数据
- 限流对比:Sentinel vs Hystrix 到底怎么选?
- Alibaba side: analysis of ten classic interview questions
- 如何借助自动化工具落地DevOps|含低代码与DevOps应用实践
- The difference between oncreate and onrestoreinstancestate recovery data of activity
- ACL-IJCAI-SIGIR顶级会议论文报告会(AIS 2022)笔记3:对话和生成
猜你喜欢

工作流引擎在vivo营销自动化中的应用实践

Digital intelligence transformation, management first | jnpf strives to build a "full life cycle management" platform

Use verdaccio to build your own NPM private library

SQL statement -- single line comment and multi line comment

The "nuclear bomb level" log4j vulnerability is still widespread and has a continuing impact

Test cases should never be used casually, recording the thinking caused by the exception of a test case

Why is digital transformation so difficult?!
![[fluent -- advanced] packaging](/img/aa/bd6ecad52cbe4a34db75f067aa4dfe.png)
[fluent -- advanced] packaging

NUC 11 build esxi 7.0.3f install network card driver-v2 (upgraded version in July 2022)

研发效能的道与术 - 道篇
随机推荐
Vscode batch delete
京东三面:我要查询千万级数据量的表,怎么操作?
视频媒介video
利用MySQL主从复制延迟拯救误删数据
Pat grade a 1048 find coins
Threads and processes
[RCTF2015]EasySQL
There are six ways to help you deal with the simpledateformat class, which is not a thread safety problem
极大似然估计
Probe of kubernetes
[e-mr] error recovery record of namenode
SQL statement -- single line comment and multi line comment
[arm learning (9) ARM compiler understanding learning (armcc/armclang)]
MySQL lock mechanism (example)
How to configure tke cluster node Max pod
Pat grade a 1045 favorite color stripe
限流对比:Sentinel vs Hystrix 到底怎么选?
Want the clouds in the picture to float? Video editing services can be achieved in three steps with one click
2022-2023 信息管理毕业设计选题题目推荐
The "nuclear bomb level" log4j vulnerability is still widespread and has a continuing impact