I simply want some elements inside a QDialog to be blinking (altering background color).
Now preferably I'd like to be able to use something that already exists and encapsulates the blinking state, i.e. blinking with css3 or maybe it is possible with QPropertyAnimation
?
Since I didn't find any nice info on that option I tried the less optimal solution:
excerpt from the Dialogs __init__
:
self.timer = QTimer()
self.timer.timeout.connect(self.update_blinking)
self.timer.start(250)
self.last_blinked = None
and
def update_blinking(self):
self.frame.setStyleSheet(
self.STYLE_BLINK_ON if self.blink else self.STYLE_BLINK_OFF)
self.blink = not self.blink
where STYLE_BLINK_ON
and STYLE_BLINK_OFF
are some css specifying the background colors.
That works but
- I find it super ugly, it feels like code from the 90s
- It isn't usable as the frequent style-update interrupts button-clicks.
Explanation for 2.: Assume the widget that should be blinking is a frame.
When a button inside that frame is clicked, the clicked
signal isn't emitted if a style-update of the frame occurs before the mouse-button is released.
A completely different solution that encapsulates things and doesn't require me to manually start a timer would of course be preferred. But I would be grateful if someone at least came up with a solution which solves point 2.