MCPcopy Create free account
hub / github.com/PyQt5/PyQtClient / RubberBandButton

Class RubberBandButton

Widgets/Buttons/RubberBandButton.py:19–118  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17
18
19class RubberBandButton(QPushButton):
20
21 def __init__(self, *args, **kwargs):
22 super(RubberBandButton, self).__init__(*args, **kwargs)
23 self.setFlat(True)
24 self.setCursor(Qt.PointingHandCursor)
25 self._width = 0
26 self._height = 0
27 self._bgcolor = QColor(Qt.green)
28
29 def paintEvent(self, event):
30 self._initAnimate()
31 painter = QStylePainter(self)
32 painter.setRenderHint(QPainter.Antialiasing, True)
33 painter.setRenderHint(QPainter.HighQualityAntialiasing, True)
34 painter.setRenderHint(QPainter.SmoothPixmapTransform, True)
35 painter.setBrush(QColor(self._bgcolor))
36 painter.setPen(QColor(self._bgcolor))
37 painter.drawEllipse(
38 QRectF((self.minimumWidth() - self._width) / 2,
39 (self.minimumHeight() - self._height) / 2, self._width,
40 self._height))
41 # 绘制本身的文字和图标
42 options = QStyleOptionButton()
43 options.initFrom(self)
44 size = options.rect.size()
45 size.transpose()
46 options.rect.setSize(size)
47 options.features = QStyleOptionButton.Flat
48 options.text = self.text()
49 options.icon = self.icon()
50 options.iconSize = self.iconSize()
51 painter.drawControl(QStyle.CE_PushButton, options)
52 event.accept()
53
54 def _initAnimate(self):
55 if hasattr(self, '_animate'):
56 return
57 self._width = self.minimumWidth() * 7 / 8
58 self._height = self.minimumHeight() * 7 / 8
59 # self._width=175
60 # self._height=175
61 wanimate = QPropertyAnimation(self, b'rWidth')
62 wanimate.setEasingCurve(QEasingCurve.OutElastic)
63 wanimate.setDuration(700)
64 wanimate.valueChanged.connect(self.update)
65 wanimate.setKeyValueAt(0, self._width)
66 # wanimate.setKeyValueAt(0.1, 180)
67 # wanimate.setKeyValueAt(0.2, 185)
68 # wanimate.setKeyValueAt(0.3, 190)
69 # wanimate.setKeyValueAt(0.4, 195)
70 wanimate.setKeyValueAt(0.5, self._width + 6)
71 # wanimate.setKeyValueAt(0.6, 195)
72 # wanimate.setKeyValueAt(0.7, 190)
73 # wanimate.setKeyValueAt(0.8, 185)
74 # wanimate.setKeyValueAt(0.9, 180)
75 wanimate.setKeyValueAt(1, self._width)
76 hanimate = QPropertyAnimation(self, b'rHeight')

Callers 2

setupUiMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected