如何将 QML 地图添加到 QGraphicsscene?

How to add QML map to QGraphicscene?

该应用程序有 QGraphicscene(mpscene)QGraphicsView(mpGraphicsView) 我正在尝试将 qml 地图对象 添加到 QGraphicscene(mpscene) 但是地图视图像弹出窗口一样单独出现window。如何将此地图添加到 QGraphicscene(mpscene)

以下是我在其他帖子中建议尝试的几种方法。

方法1

 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);    

方法2

 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);

PlaneTrack.qml 文件 window 容器中,我更改为 Item 。 以下代码将 qml 添加到图形场景。

    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