[Qt-qml] StateChangeScript - why do we have it?

Girish Ramakrishnan girish at forwardbias.in
Mon Dec 27 12:20:16 CET 2010


Hi,

On Mon, Dec 27, 2010 at 1:21 PM, Ville M. Vainio <vivainio at gmail.com> wrote:
> On Mon, Dec 27, 2010 at 5:20 AM, Girish Ramakrishnan
> <girish at forwardbias.in> wrote:
>
>> When you have multiple changes in a state, you can control when the
>> script gets executed in a transition using ScriptAction. For example,
>> if you have 3 PropertyChange and a StateChangeScript, you can have the
>> script execute after 2 PropertyChanges. With something like onEntered,
>> the script would always have to run at the beginning of the
>> transition.
>
> Why not have just ScriptAction and onEntered, then?

I think that's fine too, except that you have limited control over the script.

Is the following what you are suggesting?

State {
    onEntered: { a(); b(); }
    PropertyChanges { x: 100 }
}
Transition {
    SequentialAnimation {
        ScriptAction { script: a() }
        NumberAnimation { property: "x" }
        ScriptAction { script: b() }
    }
}

The above has tricky semantics - If I had an additional c() somewhere
in onEntered and it's missing in the Transition, when exactly does one
call c() ?

Atleast the above confusion is avoided with StateChangeScript and
ScriptAction. Put as many StateChangeScript as you want in a State { }
and control their ordering in a Transition. If a StateChangeScript is
not listed in a Transition, it gets invoked in the beginning.

Girish


More information about the Qt-qml mailing list