Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. un-binding properties in QML
Forum Updated to NodeBB v4.3 + New Features

un-binding properties in QML

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 705 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kgregory
    wrote on last edited by kgregory
    #1

    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.

    DiracsbracketD 1 Reply Last reply
    0
    • K kgregory

      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.

      DiracsbracketD Offline
      DiracsbracketD Offline
      Diracsbracket
      wrote on last edited by Diracsbracket
      #2

      @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.

      1 Reply Last reply
      3
      • K Offline
        K Offline
        kgregory
        wrote on last edited by
        #3

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

        Your answer did the trick, thanks!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved