How to add QML map to QGraphicscene?

426 views Asked by At

The app have QGraphicscene(mpscene) with QGraphicsView(mpGraphicsView) i am trying to add qml map object to QGraphicscene(mpscene) But map view come separately like popup window. How can i add this map to QGraphicscene(mpscene)?

Following are the few methods i tried as suggested in other posts.

method1

 PlaneTrack *blr2bgm = new PlaneTrack; //Cpp object set to root context
 QQmlEngine *engine = new QQmlEngine(mpGraphicsView);
 QQuickWidget *view = new QQuickWidget(engine, mpGraphicsView);
 view->setResizeMode(QQuickWidget::SizeViewToRootObject);
 view->rootContext()->setContextProperty("blr2bgm",blr2bgm);
 view->setSource(QUrl(QStringLiteral("qrc:/PlaneTrack.qml")));
 mpScene->addWidget(view);    

method2

 PlaneTrack *blr2bgm = new PlaneTrack; //Cpp object set to root context
 QQuickView *view = new QQuickView();
 view->rootContext()->setContextProperty("blr2bgm",blr2bgm);
 view->setSource(QUrl(QStringLiteral("qrc:/PlaneTrack.qml")));
 view->setResizeMode(QQuickView::SizeRootObjectToView);
 QWidget *container = QWidget::createWindowContainer(view);
 container->setMinimumSize(view->size());
 container->setFocusPolicy(Qt::TabFocus);
 mpScene->addWidget(container);
1

There are 1 answers

0
Sagar A W On BEST ANSWER

In PlaneTrack.qml file window container was there that i changed to Item. Following code adds qml to graphic scene.

    PlaneTrack *blr2bgm = new PlaneTrack; // cpp class object data interact

    QQuickWidget *view = new QQuickWidget();
    view->rootContext()->setContextProperty("blr2bgm",blr2bgm);
    view->setSource(QUrl(QStringLiteral("qrc:/PlaneTrack.qml")));
    view->setMinimumSize(300, 300);
    view->setResizeMode(QQuickWidget::SizeRootObjectToView);

    mpScene->addWidget(view); // adding to Graphic scene