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 thePropertyChangeselements. Also, I need to redundantly specifytarget: fooin NumberAnimation when it's already specified in thePropertyChangeselements.Can this redundancy be avoided? If not, why not?
-
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 thePropertyChangeselements. Also, I need to redundantly specifytarget: fooin NumberAnimation when it's already specified in thePropertyChangeselements.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
targetproperty 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
toproperty, it's not necessary to give a name to a state since you havewhencondition. And etc.