Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. C++ and QML : Using QDeclarativeEngine instead of QDeclarativeView
QtWS25 Last Chance

C++ and QML : Using QDeclarativeEngine instead of QDeclarativeView

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 5.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    YeFFreY
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • A Offline
      A Offline
      anselmolsm
      wrote on last edited by
      #2

      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.

      Anselmo L. S. Melo (anselmolsm)

      1 Reply Last reply
      0
      • Y Offline
        Y Offline
        YeFFreY
        wrote on last edited by
        #3

        Thanks !

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved