Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

un-binding properties in QML



  • In my app, I have a series of 6 "selector" buttons, that I intend to have them select which property is bound to a property of my "common" widget. Right now, I have the following bit of code in each of my buttons. This works great except that it doesn't un-do any prior bindings. So after hitting all six selector buttons, they will all be simultaneously bound to the common widget. I only want one selector bound at a time, so how do I undo the prior bindings?

    onButtonClick: {
                commonWidget.backend.color = (mySelectorWidget.color1)
                mySelectorWidget.color1 = Qt.binding(function() { return (commonWidget.backend.color)})
            }
    

    I followed the property binding guide (http://doc.qt.io/qt-5/qtqml-syntax-propertybinding.html) to come up with this code, which says that the javascript binding will undo existing bindings. However, I suppose it doesn't undo other bindings that were created using javascript as I have in my example.



  • @kgregory
    It's not very clear to me what mySelectorWidget is, but in any case, to undo a binding
    but keep the current value, you can do:

    mySelectorWidget.color1 = mySelectorWidget.color1
    

    So when clicking one button, you must undo the binding like this for the OTHER currently bound button, and then do your binding for the currently clicked button.



  • It's a specialized color picker widget that I made, but I don't think that's important.

    Your answer did the trick, thanks!


Log in to reply