MCPcopy
hub / github.com/PyQt5/PyQt / paintEvent

Method paintEvent

QPushButton/FontRotate.py:43–68  ·  view source on GitHub ↗
(self, _)

Source from the content-addressed store, hash-verified

41 self.clicked.connect(self._onClick)
42
43 def paintEvent(self, _):
44 option = QStyleOptionButton()
45 self.initStyleOption(option)
46 painter = QStylePainter(self)
47 if self._rotateAnimationStarted:
48 option.text = ""
49 painter.drawControl(QStyle.CE_PushButton, option)
50 if not self._rotateAnimationStarted:
51 return
52 painter.save()
53 font = self.font()
54 font.setPointSize(self.fontSize)
55 font.setFamily("FontAwesome")
56 painter.setFont(font)
57 # 变换坐标为正中间
58 painter.translate(self.rect().center())
59 # 旋转90度
60 painter.rotate(self._rotateAnimation.currentValue() * 30)
61 fm = self.fontMetrics()
62 # 在变换坐标后的正中间画文字
63 w = fm.width(self.LoadingText)
64 h = fm.height()
65 painter.drawText(
66 QRectF(0 - w * 2, 0 - h, w * 2 * 2, h * 2), Qt.AlignCenter,
67 self.LoadingText)
68 painter.restore()
69
70 def _onClick(self):
71 if self._rotateAnimationStarted:

Callers

nothing calls this directly

Calls 4

restoreMethod · 0.80
drawControlMethod · 0.45
widthMethod · 0.45
heightMethod · 0.45

Tested by

no test coverage detected