C++ and QML : Using QDeclarativeEngine instead of QDeclarativeView
-
wrote on 24 Sept 2010, 14:52 last edited by
I'm trying to use the QDeclarativeEngine to create my view instead of the QDeclarativeView, but the view doesn't appear. The examples in the doc always describe something like this :
@QDeclarativeEngine engine;
QDeclarativeContext *windowContext = new QDeclarativeContext(engine.rootContext());
windowContext->setContextProperty("backgroundColor", QColor(Qt::yellow));QDeclarativeComponent component(&engine, "main.qml");
QObject *window = component.create(windowContext);@
Do I need to put the window QObject in a QGraphicsView also ? or Am I doing something wrong ?
Thanks for your help
-
wrote on 24 Sept 2010, 16:35 last edited by
QDeclarativeEngine and QDeclarativeView are not equivalent.
QDeclarativeView inherits QGraphicsView and encapsulates a QGraphicsScene, QDeclarativeEngine, creates a context. So, QDeclarativeView is a convenience class which creates the basic structure so you can easily display a qml file with a single setSource().
Answering your question: You need to put this window object in a QGraphicsScene as described in "this part of the docs":http://doc.qt.nokia.com/4.7/qml-integration.html#integrating-with-a-qgraphicsview-based-ui . Attention to the qobject_cast to QGraphicsObject.
-
wrote on 27 Sept 2010, 08:36 last edited by
Thanks !
2/3