Delay switch animation

If the switch triggers heavy GUI action, like a lot of paint()s, the
concurrently running switch animation may look choppy.
A small timer makes these events execute first and the animation will
run smoothly afterwards when the event queue has been drained.
This commit is contained in:
RumovZ 2021-03-31 12:13:09 +02:00
parent c8146c13c1
commit fd4b5dc695

View file

@ -108,7 +108,8 @@ class Switch(QAbstractButton):
animation.setDuration(100)
animation.setStartValue(self.start_position)
animation.setEndValue(self.end_position)
animation.start()
# make triggered events execute first so the animation runs smoothly afterwards
QTimer.singleShot(50, animation.start)
def enterEvent(self, event: QEvent) -> None:
self.setCursor(Qt.PointingHandCursor)