import QtQuick // A label + switch. Clickable and keyboard-operable (Space/Enter). Item { id: toggle property string label: "" property string description: "" property bool checked: false signal toggled(bool value) implicitHeight: description.length > 0 ? 52 : 36 width: parent ? parent.width : implicitWidth activeFocusOnTab: true Accessible.role: Accessible.CheckBox Accessible.name: label Accessible.checked: checked Keys.onSpacePressed: { toggle.checked = !toggle.checked; toggle.toggled(toggle.checked); } Keys.onReturnPressed: Keys.onSpacePressed(event) Keys.onEnterPressed: Keys.onSpacePressed(event) Column { anchors.left: parent.left anchors.right: switchBox.left anchors.rightMargin: 16 anchors.verticalCenter: parent.verticalCenter spacing: 2 Text { width: parent.width text: toggle.label color: Theme.warmWhite font.family: Theme.family font.pixelSize: Theme.fontBody } Text { width: parent.width text: toggle.description color: Theme.muted font.family: Theme.family font.pixelSize: Theme.fontSmall wrapMode: Text.WordWrap visible: toggle.description.length > 0 } } Rectangle { id: switchBox anchors.right: parent.right anchors.verticalCenter: parent.verticalCenter width: 44 height: 24 radius: 12 color: toggle.checked ? Theme.amberDeep : Theme.border border.width: toggle.activeFocus ? 2 : 0 border.color: Theme.focusRing Rectangle { width: 18 height: 18 radius: 9 y: 3 x: toggle.checked ? parent.width - width - 3 : 3 color: toggle.checked ? Theme.warmWhite : Theme.muted Behavior on x { NumberAnimation { duration: 90 } } } MouseArea { anchors.fill: parent cursorShape: Qt.PointingHandCursor onClicked: { toggle.forceActiveFocus(); toggle.checked = !toggle.checked; toggle.toggled(toggle.checked); } } } }