PropertyAnimation in signal handler
Unsolved
QML and Qt Quick
-
According to the docs the
PropertyAnimation
can be used in signal handlers:MouseArea { anchors.fill: theObject onClicked: PropertyAnimation { target: theObject; property: "opacity"; to: 0 } }
But why is not possible to use the braces around?
MouseArea { anchors.fill: theObject onClicked: { PropertyAnimation { target: theObject; property: "opacity"; to: 0 } } }
This leads to the following error:
Expected token ,
-
Because when using braces you are now in a javascript scope, and you can't create QML objects declaratively like that in js.
What are you trying to do?
My 2 cents: I wasn't even aware that you could do that and my first reaction was disbelief. This QML feature of assigning an animation to a signal handler seems like a bad idea and isn't really intuitive.
-
@GrecKo I was trying to find a way to execute an animation without declaring it separately. In "meta-code":
onSignalTrigger: { timer.stop() doSomething() doSomethingElse() // animate property PropertyAnimation { target: theObject; property: "opacity"; to: 0 } }
The long way is:
PropertyAnimation { id: myAnim; target: theObject; property: "opacity"; to: 0 } onSignalTrigger: { timer.stop() doSomething() doSomethingElse() // animate property myAnim.start() }
I find the first syntax is more readable