按钮常用信号
This commit is contained in:
parent
73400904d2
commit
248fb468ce
5 changed files with 77 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
- [普通样式](#1普通样式)
|
||||
- [按钮底部线条进度](#2按钮底部线条进度)
|
||||
- [按钮文字旋转进度](#3按钮文字旋转进度)
|
||||
- [按钮常用信号](#4按钮常用信号)
|
||||
|
||||
## 1、普通样式
|
||||
[运行 NormalStyle.py](NormalStyle.py)
|
||||
|
@ -25,3 +26,11 @@
|
|||
利用字体,使用FontAwesome字体来显示一个圆形进度条,然后利用旋转动画
|
||||
|
||||
![FontRotate](ScreenShot/FontRotate.gif)
|
||||
|
||||
## 4、按钮常用信号
|
||||
[运行 SignalsExample.py](SignalsExample.py)
|
||||
|
||||
根据官网文档 https://doc.qt.io/qt-5/qabstractbutton.html#signals 中的信号介绍编写
|
||||
按钮的点击、按下、释放、选中信号演示
|
||||
|
||||
![SignalsExample](ScreenShot/SignalsExample.gif)
|
BIN
QPushButton/ScreenShot/SignalsExample.gif
Normal file
BIN
QPushButton/ScreenShot/SignalsExample.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 67 KiB |
65
QPushButton/SignalsExample.py
Normal file
65
QPushButton/SignalsExample.py
Normal file
|
@ -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_())
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue