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

Problem with Transitions: unnecessary call to change object properties

    XMLWordPrintable

Details

    • Windows

    Description

      Hello,
       
      I encountered strange behavior in QML when working with transitions. The main problem is that when transitioning between different states of objects, the properties of objects change several times instead of once. An example is given in the sample.
       
      More detailed description:
       
      Input: we have 2 simple QML objects inside a parent object, which has a state machine with two states. There is also a transitions element for state change animation:
       
       

      Item {
          id: mainItem
          anchors.fill: parent
          anchors.centerIn: parent
          state: "HIDDEN"
          Column {
              anchors.topMargin: 100
              anchors.fill: parent
              spacing: 10
              padding: 10
              TestItem {
                  id: testItem
                  width: 100
                  height: 100
              }
              CustomItem {
                  id: customItem
                  width: 100
                  height: 100
                  Rectangle {
                      anchors.fill: parent
                      color: "transparent"
                      border.color: "black"
                      Text {
                          anchors.fill: parent
                          text: qsTr("customitem.cpp")
                      }
                  }
                  counter: 0
              }
              OtherItem {
                  id: otherItem
                  width: 100
                  height: 100
                  opacity: 1
              }
          }
          states: [
              State {
                  name: "HIDDEN"
                  PropertyChanges {
                      target: otherItem
                      color: getGreenColor()
                      opacity: 0
                  }
                  PropertyChanges {
                      target: testItem
                      customProperty: 0
                  }
                  PropertyChanges {
                      target: customItem
                      counter: 10
                  }
              },
              State {
                  name: "ACTIVE"
                  PropertyChanges {
                      target: testItem
                      customProperty: 1
                  }
                  PropertyChanges {
                      target: otherItem
                      color: getGreenColor()
                      opacity: 1
                  }
              }
          ]
          transitions: [
              Transition {
                  from: "*"
                  to: "*"
                  PropertyAnimation {
                      target: otherItem
                      property: "opacity"
                      duration: 1000
                  }
              }
          ]
      }
      

       

      When transitioning to the HIDDEN state, the color properties of the otherItem object are set through a call to the simple getGreenColor() function, and when transitioning to the ACTIVE state, the color is set directly. The problem is that when the testItem object enters the HIDDEN state, the customProperty property changes 3 times instead of one, here is the log of the testItem.onCustomPropertyChanged function call:
       
      qml: TestItem customProperty: 0
      qml: TestItem customProperty: 1
      qml: TestItem customProperty: 0
       
      But if you don’t use functions when changing properties, then the state changes once, as expected.
       
      A quick debug showed that if a property of an object is changed with a call to the JS function, then QQuickTransitionManager sets properties for all objects in the QQuickStateAction::list, since in QQuickTransitionManagerPrivate::bindingsList it contains the binding for only this one object.
       
      Could you please clarify if such behavior is expected?

      Attachments

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

        Activity

          People

            matthias_rauter Matthias Rauter
            kbokov Bokov Konstantin
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes