MCPcopy Create free account
hub / github.com/PyQt5/PyQt / CircleProgressBar

Class CircleProgressBar

QProgressBar/RoundProgressBar.py:23–88  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21
22
23class CircleProgressBar(QWidget):
24 Color = QColor(24, 189, 155) # 圆圈颜色
25 Clockwise = True # 顺时针还是逆时针
26 Delta = 36
27
28 def __init__(self, *args, color=None, clockwise=True, **kwargs):
29 super(CircleProgressBar, self).__init__(*args, **kwargs)
30 self.angle = 0
31 self.Clockwise = clockwise
32 if color:
33 self.Color = color
34 self._timer = QTimer(self, timeout=self.update)
35 self._timer.start(100)
36
37 def paintEvent(self, event):
38 super(CircleProgressBar, self).paintEvent(event)
39 painter = QPainter(self)
40 painter.setRenderHint(QPainter.Antialiasing)
41 painter.translate(self.width() / 2, self.height() / 2)
42 side = min(self.width(), self.height())
43 painter.scale(side / 100.0, side / 100.0)
44 painter.rotate(self.angle)
45 painter.save()
46 painter.setPen(Qt.NoPen)
47 color = self.Color.toRgb()
48 for i in range(11):
49 color.setAlphaF(1.0 * i / 10)
50 painter.setBrush(color)
51 painter.drawEllipse(30, -10, 20, 20)
52 painter.rotate(36)
53 painter.restore()
54 self.angle += self.Delta if self.Clockwise else -self.Delta
55 self.angle %= 360
56
57 @pyqtProperty(QColor)
58 def color(self) -> QColor:
59 return self.Color
60
61 @color.setter
62 def color(self, color: QColor):
63 if self.Color != color:
64 self.Color = color
65 self.update()
66
67 @pyqtProperty(bool)
68 def clockwise(self) -> bool:
69 return self.Clockwise
70
71 @clockwise.setter
72 def clockwise(self, clockwise: bool):
73 if self.Clockwise != clockwise:
74 self.Clockwise = clockwise
75 self.update()
76
77 @pyqtProperty(int)
78 def delta(self) -> int:
79 return self.Delta
80

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected