Code redundancy when creating Transition



  • My code:

    states: [
        State {
            name: "pressed"; when: mouseArea.pressed
            PropertyChanges {
                target: foo
                prop1: 10
                prop2: 10
                prop3: 10
            }
        },
        State {
            name: "notPressed"; when: !mouseArea.pressed
            PropertyChanges {
                target: foo
                prop1: 1
                prop2: 1
                prop3: 1
            }
        }
    ]
    transitions: [
        Transition {
            to: "*"
            NumberAnimation {
                target: foo
                properties: "prop1,prop2,prop3"
                duration: 1000
            }
        }
    ]
    

    This works, but requires me to redundantly specify properties: "prop1,prop2,prop3" when the properties to change are already specified in the PropertyChanges elements. Also, I need to redundantly specify target: foo in NumberAnimation when it's already specified in the PropertyChanges elements.

    Can this redundancy be avoided? If not, why not?



  • @Stefan-Monov76 At firstly since you have the single target you don't need to specify target property at transition.
    At secondly you can use a specific animators, such as OpacityAnimator, ScaleAnimator, etc.

    You have to set explicitly all names of properties because this is what you want. In some cases you might want not to animate prop1.
    And this is default reaction of the engine: make change without transition (this is about performance).

    You can read more about it here: http://doc.qt.io/qt-5/qtquick-statesanimations-topic.html

    Also, you don't need to make an array if you have a single object, you don't need to explicitly set to property, it's not necessary to give a name to a state since you have when condition. And etc.



  • Set explicitly all names of properties because this is what you want. In some cases you might want not to animate prop1.
    And this is default reaction of the engine: make change without transition (this is about performance).


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.