How can i Know SwitchDelegate is checked or not?
Solved
QML and Qt Quick
-
Hello :D
i try to create a Radio with qml UI and python backend. so for radio i had a on-off widget in this case i usingSwitchDelegate
.
so how can i know it is checked or not?SwitchDelegate { id: switchDelegate x: 195 y: 123 checked: false text: qsTr("ON") onCheckedChanged: { // backend.on_off_radio(parent.checked) }
-
I can print my message in
onCheckedChanged
so this is true.
but i want to use a bool function if i want to test it checked is true or false how can be know? -
You can access the checked property directly:
onCheckedChanged: { console.debug("checked value:", checked) if(checked) console.debug("Switch is checked") else console.debug("Switch is not checked") }
from somewhere else you can access the property by the id of the object:
someFunction() { // note you used switchDelegate as id of your SwitchDelegate let isSwitchChecked = switchDelegate.checked }
or via property binding:
SwitchDelegate { id: switchDelegate2 checked: !switchDelegate.checked } Text { text: switchDelegate.checked ? "Switch is checked" : "Switch is not checked" }