-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyRotateProgress.py
87 lines (76 loc) · 2.99 KB
/
MyRotateProgress.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from PyQt5.Qt import *
class MyRotateProgress(QWidget):
PenStyleNormal = 0
PenStyleGradient = 1
PenstylePerGradient = 2
def __init__(self, width, height, parent = None):
super(MyRotateProgress, self).__init__(parent)
self.setMinimumSize(width, height)
self.now = 0;
self._timer = QTimer(self)
self._timer.timeout.connect(self.onTime)
self._timer.start(150)
self._PenStyle = MyRotateProgress.PenStyleNormal
def onTime(self):
self.now += 1
self.now = 0 if self.now >= 10 else self.now
self.update()
def paintEvent(self, QPaintEvent):
super(MyRotateProgress, self).paintEvent(QPaintEvent)
painter = QPainter(self)
# 反走样,边缘平滑
painter.setRenderHint(QPainter.Antialiasing, True)
#radius取最小边长
radius = self.width() if self.width() < self.height() else self.height()
if radius <= 0:
return
radius = radius/6
# 将圆等分为10份,分别画出10条线
per = 360/10;
painter.translate(self.width()/2, self.height()/2)
for i in range(10):
painter.save()
painter.setPen(self.getPenStyle(self._PenStyle, i))
painter.rotate(per*i)
painter.drawLine(QPoint(0, 0 + radius), QPoint(0, 0 + radius*2))
painter.restore()
def getPenStyle(self, PenStyle, PenPoint):
radius = self.width() if self.width() < self.height() else self.height()
if radius <= 0:
return
radius = radius / 6
if PenStyle == MyRotateProgress.PenStyleNormal:
if PenPoint == self.now:
return QPen(Qt.white, 3)
else:
return QPen(Qt.black, 3)
elif PenStyle == MyRotateProgress.PenStyleGradient:
point = PenPoint-self.now if PenPoint-self.now >= 0 else 10+PenPoint-self.now
return QPen(QColor(255*point/10, 255*point/10,255*point/10), 3)
elif PenStyle == MyRotateProgress.PenstylePerGradient:
if PenPoint == self.now:
gradient = QRadialGradient(0,radius, radius, 0, radius)
gradient.setColorAt(0.2,Qt.white)
gradient.setColorAt(0.6,Qt.gray)
return QPen(gradient, 3)
else:
gradient = QRadialGradient(0,radius, radius, 0, radius)
gradient.setColorAt(0.2,Qt.gray)
gradient.setColorAt(0.6,Qt.black)
return QPen(gradient, 3)
def closeEvent(self, QCloseEvent):
if self._timer.isActive():
self._timer.stop()
def hideEvent(self, QHideEvent):
if self._timer.isActive():
self._timer.stop()
def showEvent(self, QShowEvent):
if self._timer.isActive() != True:
self._timer.start()
@property
def PenStyle(self):
return self._PenStyle
@PenStyle.setter
def PenStyle(self, Value):
self._PenStyle = Value
self.update()