How to change a property binding during (after) an element creation in QML ?
-
Suppose I have a custom
CheckBox://MyCheckBox.qml CheckBox { required property QtObject proxy checked: proxy.value Binding { target: proxy property: "value" value: checked } }So the checked status of the
MyCheckBoxbound to thevalueproperty of my object (proxy) and vise-versa, i.e. I have a two-way binding.I am using my custom checkbox as follows:
//My window Item { ... MyCheckBox { id: ordinaryCheck proxy: ... } ... }Everything works as expected. But what if I need to invert the logic for some instance of
MyCheckBox: whenproxy.valueis true the checkbox is unchecked, and whenproxy.valueis false the checkbox is checked ? But this, ofc, doesn't work as I have a binding loop here if I try to do this:Item { ... MyCheckBox { id: invertedCheck proxy: ... checked: !proxy.value Binding { target: proxy.value property: "value" value: !checked } }The Qt bindings are also not an option:
//MyCheckBox.qml CheckBox { required property QtObject proxy checked: proxy.value Component.onCompleted { property.value = Qt.binding(function() { return checked }); } }I have the same binding loop error in this case.
So what is my option to reach the goal, how to alternate the binding at the moment of instantiation ?