| 19 | |
| 20 | |
| 21 | class AnimationShadowEffect(QGraphicsDropShadowEffect): |
| 22 | |
| 23 | def __init__(self, color, *args, **kwargs): |
| 24 | super(AnimationShadowEffect, self).__init__(*args, **kwargs) |
| 25 | self.setColor(color) |
| 26 | self.setOffset(0, 0) |
| 27 | self.setBlurRadius(0) |
| 28 | self._radius = 0 |
| 29 | self.animation = QPropertyAnimation(self) |
| 30 | self.animation.setTargetObject(self) |
| 31 | self.animation.setDuration(2000) # 一次循环时间 |
| 32 | self.animation.setLoopCount(-1) # 永久循环 |
| 33 | self.animation.setPropertyName(b'radius') |
| 34 | # 插入值 |
| 35 | self.animation.setKeyValueAt(0, 1) |
| 36 | self.animation.setKeyValueAt(0.5, 30) |
| 37 | self.animation.setKeyValueAt(1, 1) |
| 38 | |
| 39 | def start(self): |
| 40 | self.animation.start() |
| 41 | |
| 42 | def stop(self, r=0): |
| 43 | # 停止动画并修改半径值 |
| 44 | self.animation.stop() |
| 45 | self.radius = r |
| 46 | |
| 47 | @pyqtProperty(int) |
| 48 | def radius(self): |
| 49 | return self._radius |
| 50 | |
| 51 | @radius.setter |
| 52 | def radius(self, r): |
| 53 | self._radius = r |
| 54 | self.setBlurRadius(r) |