[Qt-qml] State transition proposal: PropertyChangesLater

Andre Somers andre at familiesomers.nl
Mon Feb 7 08:06:45 CET 2011


Op 6-2-2011 14:45, Vinayakam Murugan schreef:
>
> On Sun, Feb 6, 2011 at 5:40 AM, Thomas Perl <th.perl at gmail.com 
> <mailto:th.perl at gmail.com>> wrote:
>
>     Hi,
>
>     I often have the case where items have two states: One state being
>     "on-screen" and visible, the other state being "off-screen" and not
>     visible. I'd like to animate between those states, so that the user
>     "knows" that the view is going away and coming back. For performance
>     reasons, the "off-screen" state should set "opacity" to 0. Now, if I
>     use PropertyChanges in the state to set the opacity, the "sliding out"
>     animation isn't visible, because the property changes as soon as the
>     state is entered, therefore the animation isn't visible anymore. I'm
>     currently working around this using a SequentialAnimation and
>     ScriptAction in the transition, like this:
>
>     transitions: Transition {
>        SequentialAnimation {
>            ScriptAction { script: inner.opacity = 1 }
>            AnchorAnimation {}
>            ScriptAction { script: inner.opacity =
>     (inner.state=='onscreen') }
>        }
>     }
>
>     (where "inner" is the object that i move, and it has two states
>     "onscreen" and "offscreen")
>
>     I imagine this is a common use case. How do you handle it currently? I
>     could imagine something like a "PropertyChangesLater" being useful,
>     behaving the same way as PropertyChanges, but carrying out the changes
>     after all transitions have finished. This way, I could just say (in
>     the "offscreen" state):
>
>     PropertyChangesLater {
>        target: inner
>        opacity: 0
>     }
>
>     Does this make sense? Can this be considered for a future QML version,
>     or is there an easier, obvious way to accomplish what I'm trying to
>     do?
>
>     Attached are two files: state.qml (my current workaround) and
>     state-proposed.qml (example of how the same feature would be
>     implemented using PropertyChangesLater).
>
>
What I do is something like this:

//in definition of inner:
opacity: state == "onscreen" || onscreenTransition.running ? 1 : 0

//your transition:
transitions: [
   Transition {
        AnchorAnimation {id:onscreenTransition}
   }
]

I think that achieves what you want in a simpler way, and without having 
to introduce something like PropertyChangesLater.

HTH,

André

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt-qml/attachments/20110207/9b2703f6/attachment-0001.html 


More information about the Qt-qml mailing list