[Qt-qml] Traversing between views

Ivan De Marino ivan.de.marino at gmail.com
Fri Apr 9 16:01:17 CEST 2010


Hello.

I can't show you (yet?) my code, but I can describe a solution.
I figured out that I'm always going to be in the situation where I have a
"main view" state and, based on the user action, I will be moving to other
views/states.
So, first I created in C++ a State Machine that maps the "1 state == 1
view", so that transitions between views happens on a "logical" basis in
C++.

The StateMachine is then wrapped in a QML-invocable object (the "engine" of
my app). The QML side can, based on the operation that the user executes,
receive callbacks in C++ space. This operates on the StateMachine,
transitioning from a view-state to another.

Because you have "transitions" between states in the StateMachine, I
implement those as slots. When they get a call, I just have to handle the
switching from a QML to another.

This means: I have, for every "view" a "QDeclarativeComponent" that provides
me the actual QGraphicsObject. When I move from view-state A to B, I load
the QGraphicsObject of B and inject on the Scene.

I guess you want "transitions". Well, you have event handlers that can be
registered for when "your component is ready". What you can do is to load
the QML component on the scene and, when ready, start it's own transition on
the scene.

In this way you get a smooth transitioning between views, and it's entirely
up to you how you do it.
You could, for example, create a "BaseView.qml" that embeds all the logic to
"slide in", "fade in", "rotate in" or whatever. Then you build your own
views, as subclass of this.
Then in C++ side, you load and inject the QML of those subclasses.

I know, some code would have made my long/boring answer more "meaningful",
but I can't yet.
I will probably: hopefully I will start a open source project with this, but
that's another story.

1 last hint: when you need to use stuff like "parent.width" in your
component, and this component is "being loaded/injected". Always do stuff
like:
" parent ? parent.width : 480". This helps a lot sometimes. ;)

Ciao ciao

On 9 April 2010 12:38, <Rakesh.Mutharaju at tieto.com> wrote:

>  Hello All,
>
>                   I am quite new to this Qt Quick., Could someone tell me
> how can I traverse between views.
>
> By views I mean.,  displayables having different properties and items.
> For eg., if I have two views (defined by A.qml and B.qml each representing
> a view) I would like to know how can I change from "A" view to "B" view on
> some mouse action.
>
> I know how to capture mouse click actions using Mouse Area for visual
> items., I would like to know how is it communicated to the Model and view
> switching is done.
>
> Is there any good example in Qt sources (demos or examples) folder?
> Examples using Qt Declarative module classes?
>
>
> Thanks and Regards,
> Rakesh
>
>
>
> _______________________________________________
> Qt-qml mailing list
> Qt-qml at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-qml
>
>


-- 
Ivan De Marino | Software Engineer | France Telecom R&D UK - Orange Labs
w. +44 20 8849 5806 | m. +44 7515 955 861 | m. +44 7974 156 216
ivan[dot]demarino[at]orange-ftgroup.com |
ivan[dot]de[dot]marino[at]gmail[dot]com
www.detronizator.org | www.linkedin.com/in/ivandemarino
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt-qml/attachments/20100409/712faa56/attachment.html 


More information about the Qt-qml mailing list