如何在不阻塞循环的情况下定期更改QLabel Geometry



我确实喜欢扩展这个答案,特别是blink函数来改变标签setGeometry的几何形状,特别是标签的起始坐标。

因此,根据持续时间,标签将改变不仅color还有位置(Geometry)定期.

你能告诉我这是可能的(没有阻塞循环),我该怎么做?提前谢谢。

感谢@musicamante的建议,这里是解决方案:

self.pos_anim   = QPropertyAnimation(self, b"geometry")
def alarm_alert(self, pos1, pos2, duration=3000):
"""
Function: alarm_alert, to alarm the motion of the Animated QLabel.
---
Parameters:
@param: pos1, QRect, geometry of first position.
@param: pos2, QRect, geometry of second position.
@param:duration, int, motion duration in ms.
---
@return: None
"""
self.pos_anim.stop()
self.pos_anim.setDuration(duration)
self.pos_anim.setStartValue(pos2)
self.color_anim.setKeyValueAt(0.2, pos2)
self.color_anim.setKeyValueAt(0.6, pos1)
self.color_anim.setKeyValueAt(0.2, pos2)
self.pos_anim.setEndValue(pos1)
self.pos_anim.setLoopCount(-1)
self.pos_anim.start()

最新更新