[Qt-qml] Best practice for this QML problem
Srikanth
srikanthsombhatla at gmail.com
Fri May 13 08:34:11 CEST 2011
Hi All,
Situation: Our scenario has many pages, each page is distinct and has a
layout (vertical/horizontal), and many UI elements (like button,label,image,
couple of custom wigets etc) inside this page. A simple scenario though but
our widgets are dynamic in the sense their content (for simplicity text in
label) is updated at runtime. In other words certain properties are dynamic
in the widgets. Hence we do have a controller which takes care of synching
these properties. So far this approach is working well with QWidgets. Now
that we are replacing QWidgets with QML, we have the following approach.
Approach: We have put the controller as a QObject class and inject this
controller as a context property into QML (via QDeclarativeContext) so that
the controller is accessible in the respective qml item. Certain properties
like text in label are bound using property bindings with controller. To
make this simple for POC purpose, we are creating a QDeclarativeView and
showing the QML. Since we want to move entirely on QML, we don't want to use
QDeclarativeView for each widget anymore.
Problem: As mentioned before, we want these dynamic widgets to be placed
inside a page. We can very well generate the page's qml and load it. But
these widgets don't have any meaning without the proper controller handling
the dynamic properties. Hence I am thinking about making each widget (even a
button is customized to some extent in our case, this customization is not
the point of interest here) as a self contained QDeclarativeItem. Self
contained in the sense that the required controller is also injected as a
context property and the item is loaded and get going. I don't want to load
these QDeclarativeItems into graphics scene as I don't want to tightly bind
them to a particular QML backend. That being said, how can I do the
following ...
1. Can I load the widget as a QML Component using a QML Loader or something
and inject the QObject controller into it via QML code itself?
2. (or) If I create the self contained QDeclarativeItem, how can I place it
in QML from C++.
Is there any other better approach to this problem?
Thanks for bearing with the long post, I just want to be more explicit.
Srikanth Sombhatla
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt-qml/attachments/20110513/b4839743/attachment.html
More information about the Qt-qml
mailing list