diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs index 1cedc92..30f0a4d 100644 --- a/.settings/org.eclipse.core.resources.prefs +++ b/.settings/org.eclipse.core.resources.prefs @@ -46,6 +46,7 @@ encoding//QProxyStyle/TabTextDirection.py=utf-8 encoding//QPushButton/BottomLineProgress.py=utf-8 encoding//QPushButton/FontRotate.py=utf-8 encoding//QPushButton/NormalStyle.py=utf-8 +encoding//QPushButton/SignalsExample.py=utf-8 encoding//QScrollBar/StyleScrollBar.py=utf-8 encoding//QSlider/PaintQSlider.py=utf-8 encoding//QSlider/QssQSlider.py=utf-8 diff --git a/QPushButton/README.md b/QPushButton/README.md index 9be2175..2328a51 100644 --- a/QPushButton/README.md +++ b/QPushButton/README.md @@ -4,6 +4,7 @@ - [普通样式](#1普通样式) - [按钮底部线条进度](#2按钮底部线条进度) - [按钮文字旋转进度](#3按钮文字旋转进度) + - [按钮常用信号](#4按钮常用信号) ## 1、普通样式 [运行 NormalStyle.py](NormalStyle.py) @@ -24,4 +25,12 @@ 利用字体,使用FontAwesome字体来显示一个圆形进度条,然后利用旋转动画 -![FontRotate](ScreenShot/FontRotate.gif) \ No newline at end of file +![FontRotate](ScreenShot/FontRotate.gif) + +## 4、按钮常用信号 +[运行 SignalsExample.py](SignalsExample.py) + +根据官网文档 https://doc.qt.io/qt-5/qabstractbutton.html#signals 中的信号介绍编写 +按钮的点击、按下、释放、选中信号演示 + +![SignalsExample](ScreenShot/SignalsExample.gif) \ No newline at end of file diff --git a/QPushButton/ScreenShot/SignalsExample.gif b/QPushButton/ScreenShot/SignalsExample.gif new file mode 100644 index 0000000..4942003 Binary files /dev/null and b/QPushButton/ScreenShot/SignalsExample.gif differ diff --git a/QPushButton/SignalsExample.py b/QPushButton/SignalsExample.py new file mode 100644 index 0000000..0b3cf66 --- /dev/null +++ b/QPushButton/SignalsExample.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +Created on 2019年7月2日 +@author: Irony +@site: https://pyqt5.com https://github.com/PyQt5 +@email: 892768447@qq.com +@file: QPushButton.SignalsExample +@description: 按钮信号例子 +""" +from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton, QPlainTextEdit + + +__Author__ = "Irony" +__Copyright__ = "Copyright (c) 2019" +__Version__ = "Version 1.0" + + +class Window(QWidget): + + def __init__(self, *args, **kwargs): + super(Window, self).__init__(*args, **kwargs) + layout = QVBoxLayout(self) + + btn1 = QPushButton('按钮点击信号', self) + btn1.setObjectName('ClickBtn') + btn1.clicked.connect(self.onClicked) + + layout.addWidget(btn1) + layout.addWidget(QPushButton( + '按钮按下信号', self, objectName='PressBtn', pressed=self.onPressed)) + layout.addWidget(QPushButton( + '按钮释放信号', self, objectName='ReleaseBtn', released=self.onReleased)) + layout.addWidget(QPushButton( + '按钮选中信号', self, checkable=True, objectName='ToggleBtn', toggled=self.onToggled)) + + self.resultView = QPlainTextEdit(self) + self.resultView.setReadOnly(True) + layout.addWidget(self.resultView) + + def onClicked(self): + self.resultView.appendPlainText( + '按钮{0}被点击'.format(self.sender().objectName())) + + def onPressed(self): + self.resultView.appendPlainText( + '按钮{0}被按下'.format(self.sender().objectName())) + + def onReleased(self): + self.resultView.appendPlainText( + '按钮{0}被释放'.format(self.sender().objectName())) + + def onToggled(self, checked): + self.resultView.appendPlainText( + '按钮{0}被选中:{1}'.format(self.sender().objectName(), checked)) + + +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/README.md b/README.md index a2e57b7..a99ea20 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ https://pyqt5.com 社区是专门针对PyQt5学习和提升开设的博客网站 - [普通样式](QPushButton/NormalStyle.py) - [按钮底部线条进度](QPushButton/BottomLineProgress.py) - [按钮文字旋转进度](QPushButton/FontRotate.py) + - [按钮常用信号](QPushButton/SignalsExample.py) - [QToolButton](QToolButton) - [QRadioButton](QRadioButton) - [QCheckBox](QCheckBox)