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 ?


  • Qt Champions 2017

    @saitej said:

    QQuickView

    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.

    http://www.ics.com/blog/combining-qt-widgets-and-qml-qwidgetcreatewindowcontainer


  • 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;
    view->setSource(QUrl::fromLocalFile("qrc:/qml_maps/RectViewer.qml"));

    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
 

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