Emitting signals
Objects created from a QtCore.QObject
can emit signals. In the following example we will see how we can emit custom signals.
#!/usr/bin/python
# -*- coding: utf-8 -*- """
ZetCode PyQt4 tutorial In this example, we show how to emit a
signal. author: Jan Bodnar
website: zetcode.com
last edited: January 2015
""" import sys
from PyQt4 import QtGui, QtCore class Communicate(QtCore.QObject): closeApp = QtCore.pyqtSignal() class Example(QtGui.QMainWindow): def __init__(self):
super(Example, self).__init__() self.initUI() def initUI(self): self.c = Communicate()
self.c.closeApp.connect(self.close) self.setGeometry(300, 300, 290, 150)
self.setWindowTitle('Emit signal')
self.show() def mousePressEvent(self, event): self.c.closeApp.emit() def main(): app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_()) if __name__ == '__main__':
main()
We create a new signal called closeApp
. This signal is emitted during a mouse press event. The signal is connected to the close()
slot of the QtGui.QMainWindow
.
class Communicate(QtCore.QObject): closeApp = QtCore.pyqtSignal()
A signal is created with the QtCore.pyqtSignal()
as a class attribute of the external Communicate
class.
self.c.closeApp.connect(self.close)
The custom closeApp
signal is connected to the close()
slot of the QtGui.QMainWindow
.
def mousePressEvent(self, event): self.c.closeApp.emit()
When we click on the window with a mouse pointer, the closeApp
signal is emitted. The application terminates.
Emitting signals的更多相关文章
- [Repost]Events and Signals in PyQt4
Reference:http://zetcode.com/gui/pyqt4/eventsandsignals/ Events and Signals in PyQt4 In this part of ...
- 词频统计_输入到文件_update
/* 输入文件见337.in.txt 输出文件见338.out.txt */ #include <iostream> #include <cctype> #include &l ...
- API Design Principles -- QT Project
[the original link] One of Qt’s most reputed merits is its consistent, easy-to-learn, powerfulAPI. T ...
- QT分析之网络编程
原文地址:http://blog.163.com/net_worm/blog/static/127702419201002842553382/ 首先对Windows下的网络编程总结一下: 如果是服务器 ...
- Qt qml的软件架构设计
google: qt qml application architecture 有很多资源. 1 https://www.ics.com/blog/multilayered-architecture- ...
- event & signals & threads
The Event Systemhttp://doc.qt.io/qt-4.8/eventsandfilters.html Each thread can have its own event loo ...
- How Qt Signals and Slots Work(感觉是通过Meta根据名字来调用)
Qt is well known for its signals and slots mechanism. But how does it work? In this blog post, we wi ...
- 从发布-订阅模式谈谈 Flask 的 Signals
发布-订阅模式 发布-订阅模式,顾名思义,就像大家订报纸一样,出版社发布不同类型的报纸杂志不同的读者根据不同的需求预定符合自己口味的的报纸杂志,付费之后由邮局安排人员统一派送. 上面一段话,提到了发布 ...
- Flask备注二(Configurations, Signals)
Flask备注二(Configuration, Signals) Flask是一个使用python开发Web程序的框架.依赖于Werkzeug提供完整的WSGI支持,以及Jinja2提供templat ...
随机推荐
- Spring 什么是 IOC 控制反转 ?什么是依赖注入?spring的用处 好处 为什么要用
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha Spring是一个开源的控制反转(Inversion of Control ,IoC)和 ...
- BZOJ1509 [NOI2003]逃学的小孩 树型DP
题目: 分析: 首先明确我们是要求 min(dist[C][A],dist[C][B])+dist[A][B]. 我们把C当成树根,第一我们可以发现min里面取dist[C][A]或者dist[C][ ...
- BZOJ 1030 [JSOI2007]文本生成器(AC自动机)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1030 [题目大意] 求出包含任意一个给定串的串数量 [题解] 我们求出不包含任意一个给 ...
- [NC13C]形态形成场/[Gym100430B]Divisible Substrings
[NC13C]形态形成场/[Gym100430B]Divisible Substrings 题目大意: 有\(m(m\le26)\)个字符串替换式\(S_i(|S_i\le100|)\),表示某个大写 ...
- Dubbo整合SpringCloud图片显示问题
Dubbo整合SpringCloud图片显示问题 Tips:公司项目,记录一点经验吧,理解的不对的地方欢迎大神指点 问题:商品图片上传功能(公司没有专门文件服务器)写的保存目录直接是保存在docker ...
- 【点分治】【路径小于等于k的条数】【路径恰好等于k是否存在】
POJ1741:Tree Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 29574 Accepted: 9915 Des ...
- April Fools Day Contest 2016 E. Out of Controls
E. Out of Controls 题目连接: http://www.codeforces.com/contest/656/problem/E Description You are given a ...
- High-current supply uses standard three-terminal regulator
Voltage-regulator design for high output currents can be a critical and difficult task. Although vol ...
- 对jQuery的事件绑定的一些思考
jQuery的事件绑定 问题 首先我们看下面的一个非经常见的事件绑定代码: //example $('#dom').click(function(e){ //do something }); $('# ...
- 【Linux编程】进程标识符与fork函数
ID为0的进程一般是调度进程.常被称为交换进程(swapper),是内核中的系统进程. ID为1的进程叫做init进程,是一个普通用户进程,不属于内核,由内核调用. 一个现有进程能够调用fork函数创 ...