Skip to content

Commit 248fb46

Browse files
committed
按钮常用信号
1 parent 7340090 commit 248fb46

File tree

5 files changed

+77
-1
lines changed

5 files changed

+77
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ encoding//QProxyStyle/TabTextDirection.py=utf-8
4646
encoding//QPushButton/BottomLineProgress.py=utf-8
4747
encoding//QPushButton/FontRotate.py=utf-8
4848
encoding//QPushButton/NormalStyle.py=utf-8
49+
encoding//QPushButton/SignalsExample.py=utf-8
4950
encoding//QScrollBar/StyleScrollBar.py=utf-8
5051
encoding//QSlider/PaintQSlider.py=utf-8
5152
encoding//QSlider/QssQSlider.py=utf-8

QPushButton/README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- [普通样式](#1普通样式)
55
- [按钮底部线条进度](#2按钮底部线条进度)
66
- [按钮文字旋转进度](#3按钮文字旋转进度)
7+
- [按钮常用信号](#4按钮常用信号)
78

89
## 1、普通样式
910
[运行 NormalStyle.py](NormalStyle.py)
@@ -24,4 +25,12 @@
2425

2526
利用字体,使用FontAwesome字体来显示一个圆形进度条,然后利用旋转动画
2627

27-
![FontRotate](ScreenShot/FontRotate.gif)
28+
![FontRotate](ScreenShot/FontRotate.gif)
29+
30+
## 4、按钮常用信号
31+
[运行 SignalsExample.py](SignalsExample.py)
32+
33+
根据官网文档 https://doc.qt.io/qt-5/qabstractbutton.html#signals 中的信号介绍编写
34+
按钮的点击、按下、释放、选中信号演示
35+
36+
![SignalsExample](ScreenShot/SignalsExample.gif)
66.9 KB
Loading

QPushButton/SignalsExample.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
"""
5+
Created on 2019年7月2日
6+
@author: Irony
7+
@site: https://pyqt5.com https://github.com/PyQt5
8+
@email: 892768447@qq.com
9+
@file: QPushButton.SignalsExample
10+
@description: 按钮信号例子
11+
"""
12+
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton, QPlainTextEdit
13+
14+
15+
__Author__ = "Irony"
16+
__Copyright__ = "Copyright (c) 2019"
17+
__Version__ = "Version 1.0"
18+
19+
20+
class Window(QWidget):
21+
22+
def __init__(self, *args, **kwargs):
23+
super(Window, self).__init__(*args, **kwargs)
24+
layout = QVBoxLayout(self)
25+
26+
btn1 = QPushButton('按钮点击信号', self)
27+
btn1.setObjectName('ClickBtn')
28+
btn1.clicked.connect(self.onClicked)
29+
30+
layout.addWidget(btn1)
31+
layout.addWidget(QPushButton(
32+
'按钮按下信号', self, objectName='PressBtn', pressed=self.onPressed))
33+
layout.addWidget(QPushButton(
34+
'按钮释放信号', self, objectName='ReleaseBtn', released=self.onReleased))
35+
layout.addWidget(QPushButton(
36+
'按钮选中信号', self, checkable=True, objectName='ToggleBtn', toggled=self.onToggled))
37+
38+
self.resultView = QPlainTextEdit(self)
39+
self.resultView.setReadOnly(True)
40+
layout.addWidget(self.resultView)
41+
42+
def onClicked(self):
43+
self.resultView.appendPlainText(
44+
'按钮{0}被点击'.format(self.sender().objectName()))
45+
46+
def onPressed(self):
47+
self.resultView.appendPlainText(
48+
'按钮{0}被按下'.format(self.sender().objectName()))
49+
50+
def onReleased(self):
51+
self.resultView.appendPlainText(
52+
'按钮{0}被释放'.format(self.sender().objectName()))
53+
54+
def onToggled(self, checked):
55+
self.resultView.appendPlainText(
56+
'按钮{0}被选中:{1}'.format(self.sender().objectName(), checked))
57+
58+
59+
if __name__ == '__main__':
60+
import sys
61+
from PyQt5.QtWidgets import QApplication
62+
app = QApplication(sys.argv)
63+
w = Window()
64+
w.show()
65+
sys.exit(app.exec_())

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ https://pyqt5.com 社区是专门针对PyQt5学习和提升开设的博客网站
3434
- [普通样式](QPushButton/NormalStyle.py)
3535
- [按钮底部线条进度](QPushButton/BottomLineProgress.py)
3636
- [按钮文字旋转进度](QPushButton/FontRotate.py)
37+
- [按钮常用信号](QPushButton/SignalsExample.py)
3738
- [QToolButton](QToolButton)
3839
- [QRadioButton](QRadioButton)
3940
- [QCheckBox](QCheckBox)

0 commit comments

Comments
 (0)