Is there any way to make Behavior work on multiple attributes simultaneously to simplify the code?
ApplicationWindow {
width: 1280
height: 720
visible: true
title: qsTr("Hello World")
color:"#202020"
Rectangle{
id:rect
x:100
y:100
width: 100
height: 50
color:"red"
Behavior on x, y, width, height, color{ //there will be error here
PropertyAnimation{duration:1000}
}
}
Button{
onClicked: {
rect.x=300
rect.y=400
rect.width=200
rect.height100
rect.color="green"
}
}
}
I want all 5 attributes to have a smooth change effect, so I have to define 5 Behaviors and apply them to each of these 5 properties separately, I think this is troublesome.
Perhaps you would like to try
StateandTransitioninstead ofBehavior?You can Try it Online!
[EDIT] Another solution you may wish to consider is to use
Instantiator+PropertyAnimation. By controllingInstantiator'smodel, you can create/destroy animations as well as feed them custom values, for instance:You can Try it Online!