0

I do like to extend this answer especially the blink function to change the geometry of the label setGeometry, in particular, the starting coordinates of the label.

So according to duration, the label will change not only the color but also the position(Geometry) periodically.

Can you please tell me if that is possible (without blocking loops) and how can I do it please? thanks in advance.

Bilal
  • 3,191
  • 4
  • 21
  • 49
  • 1
    You're already using a QPropertyAnimation, why don't you add another for the geometry or pos? – musicamante May 03 '22 at 13:03
  • @musicamante Thanks for your kind advice, your suggestion should work perfectly according to the [documentation](https://doc.qt.io/qt-5/qpropertyanimation.html). – Bilal May 03 '22 at 13:07

1 Answers1

0

Thanks to the suggestion of @musicamante here is the solution:

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()
Bilal
  • 3,191
  • 4
  • 21
  • 49