当前位置:网站首页>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有一个叫“生成对话框代码”的功能,也可以生成信号和槽。
边栏推荐
- 公共数据如何兼顾开放利用和隐私安全合规?
- ZABBIX 6.2.0 deployment
- Test cases should never be used casually, recording the thinking caused by the exception of a test case
- Marxan model, reserve optimization and protection vacancy selection technology, application in invest ecosystem
- The first case in Guangdong! A company in Guangzhou was punished by the police for failing to fulfill its obligation of data security protection
- Acl-ijcai-sigir top conference paper report meeting (AIS 2022) Note 3: dialogue and generation
- Pat grade a 1048 find coins
- Analyzing method and proc in Ruby
- Sword finger offer special assault edition day 11
- [arm learning (9) ARM compiler understanding learning (armcc/armclang)]
猜你喜欢

别用Xshell了,试试这个更现代的终端连接工具

Vlang's way of beating drums
It turns out that cappuccino information security association does this. Let's have a look.

guetzli简单使用

研发效能的道与术 - 道篇

SQL statement -- single line comment and multi line comment

Pat grade a 1049 counting ones

2022 Niuke summer multi school training camp 1 (acdgij)

Collection of open source expert opinions on trusted privacy computing framework "argot"

Test cases should never be used casually, recording the thinking caused by the exception of a test case
随机推荐
Sharing of 40 completed projects of high-quality information management specialty [source code + Thesis] (VI)
FTP protocol
量化交易之数字货币篇 - 通过时间戳与方向来合并逐笔成交数据(大单合并)
guetzli简单使用
[arm learning (9) ARM compiler understanding learning (armcc/armclang)]
Nacos win10 installation and configuration tutorial
Which book is the "the Nine Yin Manual" in the field of programming
vlang捣鼓之路
TDengine 落地协鑫能科,数百亿数据压缩至 600GB
The first case in Guangdong! A company in Guangzhou was punished by the police for failing to fulfill its obligation of data security protection
Vscode batch delete
TCP 和 UDP 可以使用相同端口吗?
Re7: reading papers fla/mlac learning to predict charges for critical cases with legal basis
VS2017打开项目提示需要迁移的解决方法
A firefox/chrome plug-in that visualizes browser history
The difference and efficiency comparison of three methods of C # conversion integer
Digital currency of quantitative transactions - merge transaction by transaction data through timestamp and direction (large order consolidation)
Pat grade a 1049 counting ones
SQL statement -- single line comment and multi line comment
Pat grade a 1046 shortest distance