On 27/08/2010, at 6:52 PM, ext Wei, James wrote:
I have a QML file and I want to integrate it into a graphics view framework
based UI application written in C++.
QDeclarativeEngine *engine = new QDeclarativeEngine;
QDeclarativeComponent component(engine, QUrl::fromLocalFile("Button.qml"));
QGraphicsObject *object =
qobject_cast<QGraphicsObject *>(component.create());
scene->addItem(object);
How can I change the property of the element in C++ application?
Hi James,
You could use Qt's property system to manipulate the item (see
http://doc.qt.nokia.com/4.7-snapshot/properties.html#reading-and-writing-properties-with-the-meta-object-system
for more on using the property system). For example, assuming the above
"Button.qml" had a Rectangle as the root, you could change its color with
object->setProperty("color", QColor("green"));
You might also consider an architecture where you never manipulate the item
directly from C++; instead, expose the relevant properties/signals/slots from
C++ and write the QML to react accordingly (as described in
http://doc.qt.nokia.com/4.7-snapshot/qtbinding.html#exposing-data).
Regards,
Michael
_______________________________________________
Qt-qml mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt-qml