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. How to change a property binding during (after) an element creation in QML ?
Forum Updated to NodeBB v4.3 + New Features

How to change a property binding during (after) an element creation in QML ?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 222 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.
  • L Offline
    L Offline
    LRDPRDX
    wrote on last edited by LRDPRDX
    #1

    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 MyCheckBox bound to the value property 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: when proxy.value is true the checkbox is unchecked, and when proxy.value is 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 ?

    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