Menu in Widget embedded QQuickView



  • I have a QQuickView inside a Window container in a QMainWindow created like this:
    @
    QQuickView* viewer = new QQuickView();
    QWidget* container = createWindowContainer(viewer, this);
    ...
    setCentralWidget(container);
    @

    In QML I then create a Menu and onClicked call menu.popup(). I end up with "void QWindow::setTransientParent(QWindow*) QQuickView(0x157afa0) must be a top level window." and the menu showing in the corner of my screen rather than where I clicked.



  • You've provided not enough information. You'd better post the "Minimal Working Example":http://en.wikipedia.org/wiki/Minimal_Working_Example here.

    I hope "this post":http://blog.qt.digia.com/blog/2014/07/02/qt-weekly-16-qquickwidget/ will be useful.



  • As requested
    main.cpp
    @
    #include <QApplication>
    #include <QMainWindow>
    #include <QQuickView>

    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);

    QMainWindow mainWindow;
    QQuickView* viewer = new QQuickView();
    viewer->setResizeMode(QQuickView::SizeRootObjectToView);
    QWidget* container = QWidget::createWindowContainer(viewer, &mainWindow);
    container->setFocusPolicy(Qt::StrongFocus);
    viewer->setSource(QUrl(QStringLiteral("qrc:/main.qml")));
    
    mainWindow.setCentralWidget(container);
    mainWindow.show();
    
    return app.exec();
    

    }
    @

    main.qml
    @
    import QtQuick 2.2
    import QtQuick.Controls 1.2

    Rectangle {
    width: 1024
    height: 768

    Menu {
        id: menu
        title: "File"
        MenuItem { text: "One"}
        MenuItem { text: "Two"}
        MenuItem { text: "Three"}
    }
    
    MouseArea {
        anchors.fill: parent
        onClicked: menu.popup()
    }
    

    }
    @

    Outputs:
    void QWindow::setTransientParent(QWindow*) QQuickView(0x6a7270) must be a top level window.

    And menu ends up being placed at what looks like global screen space + offset.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.