Qml in Qdockwidget
-
Hi
I am trying to display a qml application in a dockwidget. I tried using this code but it gives an error.
QDockWidget *dock = new QDockWidget("Rectangle", this); QQuickView *view = new QQuickView; view->setSource(QUrl::fromLocalFile("qrc:/qml_maps/RectViewer.qml")); dock->setWidget(view);
RectViewer.qml is a simple rectangle.
ApplicationWindow{ id:_window visible: true Rectangle { width: 100 height: 100 color: "red" border.color: "black" border.width: 5 radius: 10 } }
I understand that setwidget requires a qwidget as the arg but how to send this qml-widget/appn in to dockwidget ?
-
@saitej said:
QQuickView
Inherits: QQuickWindow
Inherits: QWindow
Inherits: QObject and QSurfaceSo dont think u can use it as QWidget.
However, i saw mention of
QWidget *QWidget::createWindowContainer(QWindow *window, QWidget *parent=0, Qt::WindowFlags flags=0)which might work for you.
http://www.ics.com/blog/combining-qt-widgets-and-qml-qwidgetcreatewindowcontainer
-
@saitej Use QQuickWidget instead of
QWidget::createWindowContainer
. It has several advantages over it.
More info here. -
Since it is an applicationwindow (as i want menubar), it gives this warning
QQuickWidget does not support using windows as a root item. If you wish to create your root window from QML, consider using QQmlApplicationEngine instead.
If I use QQmlApplicationEngine, I will not be able to send the engine.
-
@saitej Well the error that you encountered earlier by using:
QQuickView *view = new QQuickView;
view->setSource(QUrl::fromLocalFile("qrc:/qml_maps/RectViewer.qml"));also is similar. You can't use
QQuickView
to loadWindow
orApplicationWindow
which requiresQQmlApplicationEngine
. But as per your requirement you dont want to use
QQmlApplicationEngine
. It seems you need to re-structure your requirements.