当前位置:网站首页>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有一个叫“生成对话框代码”的功能,也可以生成信号和槽。
边栏推荐
- NUC 11构建 ESXi 7.0.3f安装网卡驱动-V2(2022年7月升级版)
- Modify the password of the root user of MySQL database
- 2022 latest Beijing Construction Safety Officer simulation question bank and answers
- Guetzli simple to use
- Sharing of 40 completed projects of high-quality information management specialty [source code + Thesis] (VI)
- kubernetes之ReplicationController与ReplicaSet
- FTP protocol
- kubernetes之探针
- Pat grade a 1044 shopping in Mars
- Wechat applet - network data request
猜你喜欢

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

综合设计一个OPPE主页--布局与初始化
![[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)

IDEA 阿里云多模块部署

Alibaba side: analysis of ten classic interview questions

DTS is equipped with a new self-developed kernel, which breaks through the key technology of the three center architecture of the two places Tencent cloud database

2022-2023 topic recommendation of information management graduation project

The difference between anonymous methods and lambda expressions

Why is digital transformation so difficult?!
随机推荐
NUC 11构建 ESXi 7.0.3f安装网卡驱动-V2(2022年7月升级版)
ES:Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes
Movable view component (it can be dragged up, down, left and right)
TCP 和 UDP 可以使用相同端口吗?
Simulation of three-phase voltage source inverter based on SISOTOOL pole assignment PI parameters and pless
Nacos win10 installation and configuration tutorial
利用MySQL主从复制延迟拯救误删数据
面试时候常说的复杂度到底是什么?
guetzli简单使用
Happy 10th birthday, clojure
Pat grade a 1044 shopping in Mars
C # method to read the text content of all files in the local folder
2022 latest Beijing Construction Safety Officer simulation question bank and answers
Response object - response character data
[arm learning (9) ARM compiler understanding learning (armcc/armclang)]
movable-view 组件(可上下左右拖动 )
A firefox/chrome plug-in that visualizes browser history
Vscode batch delete
工作流引擎在vivo营销自动化中的应用实践
基于sisotool极点配置PI参数及基于Plecs的三相电压源逆变器仿真