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. Menu in Widget embedded QQuickView
Forum Update on Monday, May 27th 2025

Menu in Widget embedded QQuickView

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 2.7k 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.
  • B Offline
    B Offline
    Babalas
    wrote on 11 Aug 2014, 01:39 last edited by
    #1

    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.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      Dmitry.Sokolov
      wrote on 13 Aug 2014, 08:42 last edited by
      #2

      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.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        Babalas
        wrote on 19 Aug 2014, 01:31 last edited by
        #3

        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.

        1 Reply Last reply
        0

        1/3

        11 Aug 2014, 01:39

        • Login

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