Important: Please read the Qt Code of Conduct -

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;

    RectViewer.qml is a simple rectangle.

        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 ?

  • Lifetime Qt Champion

    @saitej said:


    Inherits: QQuickWindow
    Inherits: QWindow
    Inherits: QObject and QSurface

    So 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.

  • Moderators

    @saitej Use QQuickWidget instead of QWidget::createWindowContainer. It has several advantages over it.
    More info here.

  • @p3c0
    Thanks !!

  • @p3c0

    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.

  • Moderators

    @saitej Well the error that you encountered earlier by using:

    QQuickView *view = new QQuickView;

    also is similar. You can't use QQuickView to load Window or ApplicationWindow which requires QQmlApplicationEngine . But as per your requirement you dont want to use
    QQmlApplicationEngine. It seems you need to re-structure your requirements.

  • @p3c0

    is there something similar to dockwidgets in qml? Can gridview be used for a similar purpose?

Log in to reply