Menu in Widget embedded QQuickView
-
wrote on 11 Aug 2014, 01:39 last edited by
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.
-
wrote on 13 Aug 2014, 08:42 last edited by
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.
-
wrote on 19 Aug 2014, 01:31 last edited by
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.2Rectangle {
width: 1024
height: 768Menu { 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/3