From 41fe72522b853e932df2dba89ca8aaa8cb7b561e Mon Sep 17 00:00:00 2001 From: Benjamin Palko Date: Wed, 27 Aug 2025 09:59:49 -0400 Subject: [PATCH] styled switch --- components/StyledSwitch.qml | 38 +++++++++++++++++++++++++++++++++ modules/storybook/Storybook.qml | 1 + 2 files changed, 39 insertions(+) create mode 100644 components/StyledSwitch.qml diff --git a/components/StyledSwitch.qml b/components/StyledSwitch.qml new file mode 100644 index 0000000..e83fb24 --- /dev/null +++ b/components/StyledSwitch.qml @@ -0,0 +1,38 @@ +import qs.config +import QtQuick +import QtQuick.Controls + +Switch { + id: control + indicator: Item { + implicitWidth: 48 + implicitHeight: 26 + Rectangle { + implicitWidth: parent.width + implicitHeight: parent.height - 4 + x: control.leftPadding + y: parent.height / 2 - height / 2 + radius: 8 + color: control.checked ? Theme.palette.primary : Theme.palette.base100 + Behavior on color { + ColorAnimation { + duration: 150 + } + } + } + + Rectangle { + x: control.checked ? parent.width - 3 * width / 4 : width / 4 + y: parent.height / 2 - height / 2 + Behavior on x { + NumberAnimation { + duration: 150 + } + } + width: 26 + height: 26 + radius: 8 + color: Theme.palette.basecontent + } + } +} diff --git a/modules/storybook/Storybook.qml b/modules/storybook/Storybook.qml index d0d91cb..a7df0ee 100644 --- a/modules/storybook/Storybook.qml +++ b/modules/storybook/Storybook.qml @@ -41,6 +41,7 @@ StyledWindow { } ColumnLayout { + StyledSwitch {} Button { id: toolTipButton text: "Hello world!"