Skip to content

Commit 8b9803b

Browse files
committed
IsSignalConnected
1 parent 39d30af commit 8b9803b

File tree

5 files changed

+74
-1
lines changed

5 files changed

+74
-1
lines changed

.settings/org.eclipse.core.resources.prefs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ encoding//Demo/FacePoints.py=utf-8
66
encoding//Demo/FollowWindow.py=utf-8
77
encoding//Demo/FramelessDialog.py=utf-8
88
encoding//Demo/FramelessWindow.py=utf-8
9+
encoding//Demo/IsSignalConnected.py=utf-8
910
encoding//Demo/Lib/Application.py=utf-8
1011
encoding//Demo/Lib/FramelessWindow.py=utf-8
1112
encoding//Demo/NativeEvent.py=utf-8

Demo/IsSignalConnected.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
"""
5+
Created on 2019年2月24日
6+
@author: Irony
7+
@site: https://pyqt5.com https://github.com/892768447
8+
@email: 892768447@qq.com
9+
@file: IsSignalConnected
10+
@description: 判断信号是否连接
11+
"""
12+
13+
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton, QTextBrowser
14+
15+
16+
__Author__ = """By: Irony
17+
QQ: 892768447
18+
Email: 892768447@qq.com"""
19+
__Copyright__ = 'Copyright (c) 2019 Irony'
20+
__Version__ = 1.0
21+
22+
23+
class Window(QWidget):
24+
25+
def __init__(self, *args, **kwargs):
26+
super(Window, self).__init__(*args, **kwargs)
27+
layout = QVBoxLayout(self)
28+
self.button1 = QPushButton('已连接', self, clicked=self.doTest)
29+
self.button2 = QPushButton('未连接', self)
30+
self.retView = QTextBrowser(self)
31+
layout.addWidget(self.button1)
32+
layout.addWidget(self.button2)
33+
layout.addWidget(self.retView)
34+
35+
def doTest(self):
36+
self.retView.append("""
37+
# button1 clicked 是否连接: %s
38+
# button2 clicked 是否连接: %s
39+
""" % (
40+
self.isSignalConnected(self.button1, 'clicked()'),
41+
self.isSignalConnected(self.button2, 'clicked()')
42+
))
43+
44+
def isSignalConnected(self, obj, name):
45+
"""判断信号是否连接
46+
:param obj: 对象
47+
:param name: 信号名,如 clicked()
48+
"""
49+
index = obj.metaObject().indexOfMethod(name)
50+
if index > -1:
51+
method = obj.metaObject().method(index)
52+
if method:
53+
return obj.isSignalConnected(method)
54+
return False
55+
56+
57+
if __name__ == '__main__':
58+
import sys
59+
from PyQt5.QtWidgets import QApplication
60+
app = QApplication(sys.argv)
61+
w = Window()
62+
w.show()
63+
sys.exit(app.exec_())

Demo/README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- [背景连线动画](#17、背景连线动画)
2020
- [无边框圆角对话框](#18、无边框圆角对话框)
2121
- [调整窗口显示边框](#19、调整窗口显示边框)
22+
- [判断信号是否连接](#20、判断信号是否连接)
2223

2324
## 1、重启窗口Widget
2425
[运行 RestartWindow.py](RestartWindow.py)
@@ -194,4 +195,11 @@ PyQt 结合 Opencv 进行人脸检测;
194195

195196
好处在于可以减少窗口更新的次数(用途有频繁渲染的界面)
196197

197-
![ShowFrameWhenDrag](ScreenShot/ShowFrameWhenDrag.gif)
198+
![ShowFrameWhenDrag](ScreenShot/ShowFrameWhenDrag.gif)
199+
200+
## 20、判断信号是否连接
201+
[运行 IsSignalConnected.py](IsSignalConnected.py)
202+
203+
通过 `isSignalConnected` 判断是否连接
204+
205+
![IsSignalConnected](ScreenShot/IsSignalConnected.png)

Demo/ScreenShot/IsSignalConnected.png

8.43 KB
Loading

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ https://pyqt5.com 社区是专门针对PyQt5学习和提升开设的博客网站
182182
- [人脸特征点](Demo/FacePoints.py)
183183
- [使用Threading](Demo/QtThreading.py)
184184
- [背景连线动画](Demo/CircleLine.py)
185+
- [判断信号是否连接](Demo/IsSignalConnected.py)
185186

186187
# QQ群
187188

0 commit comments

Comments
 (0)