各类进度条

This commit is contained in:
Irony 2018-09-04 12:56:32 +08:00
parent cef020d4ec
commit 3a0a113448
7 changed files with 163 additions and 22 deletions

View file

@ -87,6 +87,8 @@ encoding//\u754C\u9762\u7F8E\u5316/QSS\u7F8E\u5316\u4F8B\u5B50/QPushButton\u6309
encoding//\u754C\u9762\u7F8E\u5316/QScrollBar\u6EDA\u52A8\u6761\u6837\u5F0F/ScrollBar.py=utf-8
encoding//\u754C\u9762\u7F8E\u5316/QSlider\u7F8E\u5316/PaintQSlider.py=utf-8
encoding//\u754C\u9762\u7F8E\u5316/QSlider\u7F8E\u5316/QssQSlider.py=utf-8
encoding//\u754C\u9762\u7F8E\u5316/\u5404\u7C7B\u8FDB\u5EA6\u6761/CircleProgressBar.py=utf-8
encoding//\u754C\u9762\u7F8E\u5316/\u5404\u7C7B\u8FDB\u5EA6\u6761/Test.py=utf-8
encoding//\u754C\u9762\u7F8E\u5316/\u6C34\u6CE2\u7EB9\u8FDB\u5EA6\u6761/ProgressBar.py=utf-8
encoding//\u754C\u9762\u7F8E\u5316/\u6C34\u6CE2\u7EB9\u8FDB\u5EA6\u6761/TestWidget.py=utf-8
encoding//\u7A0B\u5E8F\u91CD\u542F/AutoRestart.py=utf-8

View file

@ -70,6 +70,7 @@
- [4.8 折叠动画效果](partner_625781186/2.折叠控件/)
- [4.9 水波纹进度条](界面美化/水波纹进度条)
- [4.10 QSlider美化](界面美化/QSlider美化)
- [4.11 各类进度条](界面美化/各类进度条)

View file

@ -20,3 +20,5 @@
### [7.QPushButton进度动画](QPushButton进度动画/)
### [7.水波纹进度条](水波纹进度条/)
### [8.各类进度条](各类进度条/)

View file

@ -0,0 +1,96 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on 2018年9月4日
@author: Irony
@site: https://github.com/892768447
@email: 892768447@qq.com
@file: 界面美化.圆形进度条.CircleProgressBar
@description:
"""
from PyQt5.QtCore import QSize, pyqtProperty, QTimer, Qt
from PyQt5.QtGui import QColor, QPainter
from PyQt5.QtWidgets import QWidget
__Author__ = """By: Irony
QQ: 892768447
Email: 892768447@qq.com"""
__Copyright__ = "Copyright (c) 2018 Irony"
__Version__ = "Version 1.0"
class CircleProgressBar(QWidget):
Color = QColor(24, 189, 155) # 圆圈颜色
Clockwise = True # 顺时针还是逆时针
Delta = 36
def __init__(self, *args, **kwargs):
super(CircleProgressBar, self).__init__(*args, **kwargs)
self.angle = 0
self._timer = QTimer(self, timeout=self.update)
self._timer.start(100)
def paintEvent(self, event):
super(CircleProgressBar, self).paintEvent(event)
painter = QPainter(self)
painter.setRenderHint(QPainter.Antialiasing)
painter.translate(self.width() / 2, self.height() / 2)
side = min(self.width(), self.height())
painter.scale(side / 100.0, side / 100.0)
painter.rotate(self.angle)
painter.save()
painter.setPen(Qt.NoPen)
color = self.Color
for i in range(11):
color.setAlphaF(1.0 * i / 10)
painter.setBrush(color)
painter.drawEllipse(30, -10, 20, 20)
painter.rotate(36)
painter.restore()
self.angle += self.Delta if self.Clockwise else -self.Delta
self.angle %= 360
@pyqtProperty(QColor)
def color(self) -> QColor:
return self.Color
@color.setter
def color(self, color: QColor):
if self.Color != color:
self.Color = color
self.update()
@pyqtProperty(bool)
def clockwise(self) -> bool:
return self.Clockwise
@clockwise.setter
def clockwise(self, clockwise: bool):
if self.Clockwise != clockwise:
self.Clockwise = clockwise
self.update()
@pyqtProperty(int)
def delta(self) -> int:
return self.Delta
@delta.setter
def delta(self, delta: int):
if self.delta != delta:
self.delta = delta
self.update()
def sizeHint(self) -> QSize:
return QSize(100, 100)
if __name__ == '__main__':
import sys
from PyQt5.QtWidgets import QApplication
app = QApplication(sys.argv)
w = CircleProgressBar()
w.show()
sys.exit(app.exec_())

View file

@ -0,0 +1,5 @@
# 各类进度条
### [1.CircleProgressBar](各类进度条/CircleProgressBar.py)
![1](ScreenShot/1.gif)

Binary file not shown.

After

Width:  |  Height:  |  Size: 135 KiB

View file

@ -0,0 +1,35 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on 2018年9月4日
@author: Irony
@site: https://github.com/892768447
@email: 892768447@qq.com
@file: Test
@description:
"""
from PyQt5.QtWidgets import QWidget, QFormLayout
__Author__ = """By: Irony
QQ: 892768447
Email: 892768447@qq.com"""
__Copyright__ = "Copyright (c) 2018 Irony"
__Version__ = "Version 1.0"
class Window(QWidget):
def __init__(self, *args, **kwargs):
super(Window, self).__init__(*args, **kwargs)
layout = QFormLayout(self)
if __name__ == '__main__':
import sys
from PyQt5.QtWidgets import QApplication
app = QApplication(sys.argv)
w = Window()
w.show()
sys.exit(app.exec_())