From 99f4f68aca82541d61938469bc04e3b06430ff1b Mon Sep 17 00:00:00 2001 From: Matthias Metelka <62722460+kleinerpirat@users.noreply.github.com> Date: Mon, 15 Aug 2022 05:05:20 +0200 Subject: [PATCH] Make switch knob smaller than path (#2008) to ensure contrast when we move to a lighter window-bg color. --- qt/aqt/switch.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/qt/aqt/switch.py b/qt/aqt/switch.py index 2d8a610e1..ca92fafbc 100644 --- a/qt/aqt/switch.py +++ b/qt/aqt/switch.py @@ -14,8 +14,6 @@ class Switch(QAbstractButton): The suppoorted slots are toggle(), for an animated transition, and setChecked(). """ - _margin: int = 2 - def __init__( self, radius: int = 10, @@ -33,9 +31,10 @@ class Switch(QAbstractButton): self._right_label = right_label self._left_color = left_color self._right_color = right_color - self._path_radius = radius - self._margin - self._knob_radius = self._left_position = self._position = radius - self._right_position = 3 * self._path_radius + self._margin + self._path_radius = radius + self._knob_radius = radius - 1 + self._left_position = self._position = radius + self._right_position = 3 * self._path_radius @pyqtProperty(int) # type: ignore def position(self) -> int: @@ -65,8 +64,8 @@ class Switch(QAbstractButton): def sizeHint(self) -> QSize: return QSize( - 4 * self._path_radius + 2 * self._margin, - 2 * self._path_radius + 2 * self._margin, + 4 * self._path_radius, + 2 * self._path_radius, ) def setChecked(self, checked: bool) -> None: @@ -85,17 +84,17 @@ class Switch(QAbstractButton): def _paint_path(self, painter: QPainter) -> None: painter.setBrush(QBrush(self.path_color)) rectangle = QRectF( - self._margin, - self._margin, - self.width() - 2 * self._margin, - self.height() - 2 * self._margin, + 0, + 0, + self.width(), + self.height(), ) painter.drawRoundedRect(rectangle, self._path_radius, self._path_radius) def _current_knob_rectangle(self) -> QRectF: return QRectF( self.position - self._knob_radius, # type: ignore - 0, + 1, 2 * self._knob_radius, 2 * self._knob_radius, )