Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-56272

QML Binding {} Type doesn't restore previously set value in conditional case

XMLWordPrintable

      import QtQuick 2.4
      
      Rectangle {
        width: 400
        height: 500
      
        anchors.fill: parent
        color: "red"
      
        Binding on color {
          when: ma.pressed
          value: ma.mouseX % 2 ? "green" : "blue"
        }
      
        MouseArea {
          id: ma
          anchors.fill: parent
        }
      }
      

      According Binding type docs:

      In some cases you may want to modify the value of a property when a certain condition is met but leave it unmodified otherwise. Often, it's not possible to do this with direct bindings, as you have to supply values for all possible branches.
      [...]
      The Binding type restores any previously set direct bindings on the property.

      Now I know that in my case it's not properly a binding, but a static value in fact setting color: { "red" } would make this to work, but I was expecting the binding to be completely set back to the "default" value (or to the component customer-set value) once invalid.

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            mbrasser Michael Brasser
            3v1n0 Marco Trevisan
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes