(QML syntax - Basics) How to implement an on-off interaction on a switch
-
wrote on 28 Mar 2021, 18:42 last edited by ACaldas
Gents, sorry for the very newbie's question.
I have a custom switch "ca" that I'm trying to interact with another "cb" into a main.qml. The "ca" switch instance should enable (e.g. onToggled - in "on" position) "cb" and disable it in off position. I'm ok doing the first behavior but no idea on how to make the "cb" switch turn back to their initial state via the master "ca" switch. Could anyone help me please? Thanks.My custom switch "ca" inside the main.qml goes like this
CustomSC { ... onToggled: cb.enabled = false }
-
wrote on 28 Mar 2021, 19:52 last edited by ACaldas
-
Gents, sorry for the very newbie's question.
I have a custom switch "ca" that I'm trying to interact with another "cb" into a main.qml. The "ca" switch instance should enable (e.g. onToggled - in "on" position) "cb" and disable it in off position. I'm ok doing the first behavior but no idea on how to make the "cb" switch turn back to their initial state via the master "ca" switch. Could anyone help me please? Thanks.My custom switch "ca" inside the main.qml goes like this
CustomSC { ... onToggled: cb.enabled = false }
wrote on 28 Mar 2021, 20:03 last edited by@ACaldas said in (QML syntax - Basics) How to implement an on-off interaction on a switch:
onToggled: cb.enabled = false
where do you set "enabled" back to true ?
-
@ACaldas said in (QML syntax - Basics) How to implement an on-off interaction on a switch:
onToggled: cb.enabled = false
where do you set "enabled" back to true ?
wrote on 28 Mar 2021, 20:06 last edited by@LeLev I didn't. No idea on how to do.
-
wrote on 28 Mar 2021, 20:23 last edited by
This is my CustomSC.qml
import QtQuick 2.12 import QtQuick.Controls 2.12 SwitchDelegate { id: sDeleg text: qsTr("SwitchDelegate") spacing: 10 rightPadding: 2 leftPadding: 2 bottomPadding: 0 topPadding: 0 checked: false contentItem: Text { text: sDeleg.text font: sDeleg.font opacity: enabled ? 1.0 : 0.3 color: sDeleg.down ? "#21be2b" : "#a9a9a9" elide: Text.ElideRight verticalAlignment: Text.AlignVCenter leftPadding: 0 rightPadding: 38 } indicator: Rectangle { implicitWidth: 34 implicitHeight: 16 x: sDeleg.width - width - sDeleg.rightPadding y: parent.height / 2 - height / 2 radius: 8 color: sDeleg.checked ? "#17a81a" : "transparent" border.color: sDeleg.checked ? "#17a81a" : "#cccccc" Rectangle { x: sDeleg.checked ? parent.width - width : 0 width: 16 height: 16 radius: 8 color: sDeleg.down ? "#cccccc" : "#ffffff" border.color: sDeleg.checked ? (sDeleg.down ? "#17a81a" : "#21be2b") : "#999999" } } background: Rectangle { implicitWidth: 100 implicitHeight: 30 visible: sDeleg.down || sDeleg.highlighted color: sDeleg.down ? "#00000000" : "#00000000" } }
-
wrote on 28 Mar 2021, 21:25 last edited by
6/6