LfSlider
This commit is contained in:
parent
1f0491f1c7
commit
2a54e678ae
4 changed files with 92 additions and 1 deletions
82
QSlider/LfSlider.py
Normal file
82
QSlider/LfSlider.py
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
"""
|
||||||
|
Created on 2021/4/9
|
||||||
|
@author: Irony
|
||||||
|
@site: https://github.com/PyQt5
|
||||||
|
@email: 892768447@qq.com
|
||||||
|
@file: LfSlider
|
||||||
|
@description: 降低值变化频率
|
||||||
|
"""
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
from PyQt5.QtCore import pyqtSignal, QTimer, Qt
|
||||||
|
from PyQt5.QtWidgets import QSlider, QWidget, QVBoxLayout, QPlainTextEdit, QHBoxLayout, QGroupBox
|
||||||
|
|
||||||
|
|
||||||
|
class LfSlider(QSlider):
|
||||||
|
valueChanged = pyqtSignal(int)
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
delay = kwargs.pop('delay', 500)
|
||||||
|
super(LfSlider, self).__init__(*args, **kwargs)
|
||||||
|
self.lastValue = self.value()
|
||||||
|
self.uTimer = QTimer(self)
|
||||||
|
self.uTimer.timeout.connect(self.onValueChanged)
|
||||||
|
self.uTimer.start(delay)
|
||||||
|
|
||||||
|
def onValueChanged(self):
|
||||||
|
if self.lastValue != self.value():
|
||||||
|
self.lastValue = self.value()
|
||||||
|
self.valueChanged.emit(self.lastValue)
|
||||||
|
|
||||||
|
|
||||||
|
class TestWindow(QWidget):
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(TestWindow, self).__init__(*args, **kwargs)
|
||||||
|
layout = QHBoxLayout(self)
|
||||||
|
|
||||||
|
# 左侧原始
|
||||||
|
left_group = QGroupBox('原始QSlider', self)
|
||||||
|
left_layout = QVBoxLayout(left_group)
|
||||||
|
self.leftLabel = QPlainTextEdit(self)
|
||||||
|
left_layout.addWidget(self.leftLabel)
|
||||||
|
|
||||||
|
self.leftSlider = QSlider(Qt.Horizontal, self)
|
||||||
|
self.leftSlider.valueChanged.connect(self.onLeftChanged)
|
||||||
|
left_layout.addWidget(self.leftSlider)
|
||||||
|
|
||||||
|
layout.addWidget(left_group)
|
||||||
|
|
||||||
|
# 右侧低频率变化
|
||||||
|
right_group = QGroupBox('LfSlider', self)
|
||||||
|
right_layout = QVBoxLayout(right_group)
|
||||||
|
self.rightLabel = QPlainTextEdit(self)
|
||||||
|
right_layout.addWidget(self.rightLabel)
|
||||||
|
|
||||||
|
self.rightSlider = LfSlider(Qt.Horizontal, self)
|
||||||
|
self.rightSlider.valueChanged.connect(self.onRightChanged)
|
||||||
|
right_layout.addWidget(self.rightSlider)
|
||||||
|
|
||||||
|
layout.addWidget(right_group)
|
||||||
|
|
||||||
|
def onLeftChanged(self, value):
|
||||||
|
self.leftLabel.appendPlainText(datetime.now().strftime("[%H:%M:%S.%f] ") + str(value))
|
||||||
|
|
||||||
|
def onRightChanged(self, value):
|
||||||
|
self.rightLabel.appendPlainText(datetime.now().strftime("[%H:%M:%S.%f] ") + str(value))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
import sys
|
||||||
|
import cgitb
|
||||||
|
|
||||||
|
cgitb.enable(format='text')
|
||||||
|
from PyQt5.QtWidgets import QApplication
|
||||||
|
|
||||||
|
app = QApplication(sys.argv)
|
||||||
|
w = TestWindow()
|
||||||
|
w.show()
|
||||||
|
sys.exit(app.exec_())
|
|
@ -3,6 +3,7 @@
|
||||||
- 目录
|
- 目录
|
||||||
- [滑动条点击定位](#1滑动条点击定位)
|
- [滑动条点击定位](#1滑动条点击定位)
|
||||||
- [双层圆环样式](#2双层圆环样式)
|
- [双层圆环样式](#2双层圆环样式)
|
||||||
|
- [低频率值变化](#3低频率值变化)
|
||||||
|
|
||||||
## 1、滑动条点击定位
|
## 1、滑动条点击定位
|
||||||
[运行 ClickJumpSlider.py](ClickJumpSlider.py)
|
[运行 ClickJumpSlider.py](ClickJumpSlider.py)
|
||||||
|
@ -43,4 +44,11 @@ def mousePressEvent(self, event):
|
||||||
[运行 QssQSlider.py](QssQSlider.py) | [运行 PaintQSlider.py](PaintQSlider.py)
|
[运行 QssQSlider.py](QssQSlider.py) | [运行 PaintQSlider.py](PaintQSlider.py)
|
||||||
|
|
||||||
![QssQSlider](ScreenShot/QssQSlider.gif)
|
![QssQSlider](ScreenShot/QssQSlider.gif)
|
||||||
![PaintQSlider](ScreenShot/PaintQSlider.gif)
|
![PaintQSlider](ScreenShot/PaintQSlider.gif)
|
||||||
|
|
||||||
|
## 3、低频率值变化
|
||||||
|
[运行 LfSlider.py](LfSlider.py)
|
||||||
|
|
||||||
|
覆盖了`valueChanged`信号,通过使用定时器来延迟发送值变化,如果无法覆盖信号则可以自定义一个新的信号
|
||||||
|
|
||||||
|
![LfSlider](ScreenShot/LfSlider.gif)
|
||||||
|
|
BIN
QSlider/ScreenShot/LfSlider.gif
Normal file
BIN
QSlider/ScreenShot/LfSlider.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 483 KiB |
|
@ -100,6 +100,7 @@ https://pyqt.site 论坛是专门针对PyQt5学习和提升开设的网站,分
|
||||||
- [QSlider](QSlider)
|
- [QSlider](QSlider)
|
||||||
- [滑动条点击定位](QSlider/ClickJumpSlider.py)
|
- [滑动条点击定位](QSlider/ClickJumpSlider.py)
|
||||||
- [双层圆环样式](QSlider/QssQSlider.py)
|
- [双层圆环样式](QSlider/QssQSlider.py)
|
||||||
|
- [低频率值变化](QSlider/LfSlider.py)
|
||||||
|
|
||||||
- Display Widgets
|
- Display Widgets
|
||||||
- [QLabel](QLabel)
|
- [QLabel](QLabel)
|
||||||
|
|
Loading…
Reference in a new issue