Hide note/card switch label during animation (#2177)

* Hide note/card switch label during animation

* Satisfy mypy
This commit is contained in:
Aristotelis 2022-11-03 04:24:52 +01:00 committed by GitHub
parent 84935bee34
commit dba4925aba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -38,6 +38,7 @@ class Switch(QAbstractButton):
self._right_knob_position = self.width - self._path_radius self._right_knob_position = self.width - self._path_radius
self._left_label_position = self._label_padding / 2 self._left_label_position = self._label_padding / 2
self._right_label_position = 2 * self._knob_radius self._right_label_position = 2 * self._knob_radius
self._hide_label: bool = False
@pyqtProperty(int) # type: ignore @pyqtProperty(int) # type: ignore
def position(self) -> int: def position(self) -> int:
@ -107,7 +108,8 @@ class Switch(QAbstractButton):
painter.setRenderHint(QPainter.RenderHint.Antialiasing, True) painter.setRenderHint(QPainter.RenderHint.Antialiasing, True)
painter.setPen(Qt.PenStyle.NoPen) painter.setPen(Qt.PenStyle.NoPen)
self._paint_path(painter) self._paint_path(painter)
self._paint_label(painter) if not self._hide_label:
self._paint_label(painter)
self._paint_knob(painter) self._paint_knob(painter)
def _current_path_rectangle(self) -> QRectF: def _current_path_rectangle(self) -> QRectF:
@ -176,5 +178,14 @@ class Switch(QAbstractButton):
animation.setDuration(100) animation.setDuration(100)
animation.setStartValue(self.start_position) animation.setStartValue(self.start_position)
animation.setEndValue(self.end_position) animation.setEndValue(self.end_position)
# hide label during animation
self._hide_label = True
self.update()
def on_animation_finished() -> None:
self._hide_label = False
self.update()
qconnect(animation.finished, on_animation_finished)
# make triggered events execute first so the animation runs smoothly afterwards # make triggered events execute first so the animation runs smoothly afterwards
QTimer.singleShot(50, animation.start) QTimer.singleShot(50, animation.start)