diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs index cfd34c0..7439a6e 100644 --- a/.settings/org.eclipse.core.resources.prefs +++ b/.settings/org.eclipse.core.resources.prefs @@ -6,6 +6,7 @@ encoding//Demo/FacePoints.py=utf-8 encoding//Demo/FollowWindow.py=utf-8 encoding//Demo/FramelessDialog.py=utf-8 encoding//Demo/FramelessWindow.py=utf-8 +encoding//Demo/IsSignalConnected.py=utf-8 encoding//Demo/Lib/Application.py=utf-8 encoding//Demo/Lib/FramelessWindow.py=utf-8 encoding//Demo/NativeEvent.py=utf-8 diff --git a/Demo/IsSignalConnected.py b/Demo/IsSignalConnected.py new file mode 100644 index 0000000..4dbb19e --- /dev/null +++ b/Demo/IsSignalConnected.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +Created on 2019年2月24日 +@author: Irony +@site: https://pyqt5.com https://github.com/892768447 +@email: 892768447@qq.com +@file: IsSignalConnected +@description: 判断信号是否连接 +""" + +from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton, QTextBrowser + + +__Author__ = """By: Irony +QQ: 892768447 +Email: 892768447@qq.com""" +__Copyright__ = 'Copyright (c) 2019 Irony' +__Version__ = 1.0 + + +class Window(QWidget): + + def __init__(self, *args, **kwargs): + super(Window, self).__init__(*args, **kwargs) + layout = QVBoxLayout(self) + self.button1 = QPushButton('已连接', self, clicked=self.doTest) + self.button2 = QPushButton('未连接', self) + self.retView = QTextBrowser(self) + layout.addWidget(self.button1) + layout.addWidget(self.button2) + layout.addWidget(self.retView) + + def doTest(self): + self.retView.append(""" + # button1 clicked 是否连接: %s + # button2 clicked 是否连接: %s + """ % ( + self.isSignalConnected(self.button1, 'clicked()'), + self.isSignalConnected(self.button2, 'clicked()') + )) + + def isSignalConnected(self, obj, name): + """判断信号是否连接 + :param obj: 对象 + :param name: 信号名,如 clicked() + """ + index = obj.metaObject().indexOfMethod(name) + if index > -1: + method = obj.metaObject().method(index) + if method: + return obj.isSignalConnected(method) + return False + + +if __name__ == '__main__': + import sys + from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) + w = Window() + w.show() + sys.exit(app.exec_()) diff --git a/Demo/README.md b/Demo/README.md index a3c3cb9..00ed0be 100644 --- a/Demo/README.md +++ b/Demo/README.md @@ -19,6 +19,7 @@ - [背景连线动画](#17、背景连线动画) - [无边框圆角对话框](#18、无边框圆角对话框) - [调整窗口显示边框](#19、调整窗口显示边框) + - [判断信号是否连接](#20、判断信号是否连接) ## 1、重启窗口Widget [运行 RestartWindow.py](RestartWindow.py) @@ -194,4 +195,11 @@ PyQt 结合 Opencv 进行人脸检测; 好处在于可以减少窗口更新的次数(用途有频繁渲染的界面) -![ShowFrameWhenDrag](ScreenShot/ShowFrameWhenDrag.gif) \ No newline at end of file +![ShowFrameWhenDrag](ScreenShot/ShowFrameWhenDrag.gif) + +## 20、判断信号是否连接 +[运行 IsSignalConnected.py](IsSignalConnected.py) + +通过 `isSignalConnected` 判断是否连接 + +![IsSignalConnected](ScreenShot/IsSignalConnected.png) \ No newline at end of file diff --git a/Demo/ScreenShot/IsSignalConnected.png b/Demo/ScreenShot/IsSignalConnected.png new file mode 100644 index 0000000..e87aaef Binary files /dev/null and b/Demo/ScreenShot/IsSignalConnected.png differ diff --git a/README.md b/README.md index 74a2ab8..0f4eed4 100644 --- a/README.md +++ b/README.md @@ -182,6 +182,7 @@ https://pyqt5.com 社区是专门针对PyQt5学习和提升开设的博客网站 - [人脸特征点](Demo/FacePoints.py) - [使用Threading](Demo/QtThreading.py) - [背景连线动画](Demo/CircleLine.py) + - [判断信号是否连接](Demo/IsSignalConnected.py) # QQ群