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

Class ZoomButton

Test/ButtomZoom.py:20–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18
19
20class ZoomButton(QPushButton):
21
22 def __init__(self, *args, **kwargs):
23 super(ZoomButton, self).__init__(*args, **kwargs)
24 self._animation = QPropertyAnimation(
25 self, b'geometry', self, duration=200)
26
27 def updatePos(self):
28 # 记录自己的固定的geometry值
29 self._geometry = self.geometry()
30 self._rect = QRect(
31 self._geometry.x() - 6,
32 self._geometry.y() - 2,
33 self._geometry.width() + 12,
34 self._geometry.height() + 4
35 )
36
37 def showEvent(self, event):
38 super(ZoomButton, self).showEvent(event)
39 self.updatePos()
40
41 def enterEvent(self, event):
42 super(ZoomButton, self).enterEvent(event)
43 self._animation.stop() # 停止动画
44 # 修改动画的开始值
45 self._animation.setStartValue(self._geometry)
46 # 修改动画的终止值
47 self._animation.setEndValue(self._rect)
48 self._animation.start()
49
50 def leaveEvent(self, event):
51 super(ZoomButton, self).leaveEvent(event)
52 self._animation.stop() # 停止动画
53 # 修改动画的开始值
54 self._animation.setStartValue(self._rect)
55 # 修改动画的终止值
56 self._animation.setEndValue(self._geometry)
57 self._animation.start()
58
59 def mousePressEvent(self, event):
60 self._animation.stop() # 停止动画
61 # 修改动画的开始值
62 self._animation.setStartValue(self._rect)
63 # 修改动画的终止值
64 self._animation.setEndValue(self._geometry)
65 self._animation.start()
66 super(ZoomButton, self).mousePressEvent(event)
67
68
69class Window(QWidget):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected