Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qml in Qdockwidget
Qt 6.11 is out! See what's new in the release blog

Qml in Qdockwidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 6.6k Views 3 Watching
  • 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.
  • saitejS Offline
    saitejS Offline
    saitej
    wrote on last edited by saitej
    #1

    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 ?

    p3c0P 1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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

      1 Reply Last reply
      2
      • saitejS saitej

        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 ?

        p3c0P Offline
        p3c0P Offline
        p3c0
        Moderators
        wrote on last edited by
        #3

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

        157

        saitejS 2 Replies Last reply
        2
        • p3c0P p3c0

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

          saitejS Offline
          saitejS Offline
          saitej
          wrote on last edited by
          #4

          @p3c0
          Thanks !!

          1 Reply Last reply
          0
          • p3c0P p3c0

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

            saitejS Offline
            saitejS Offline
            saitej
            wrote on last edited by saitej
            #5

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

            p3c0P 1 Reply Last reply
            0
            • saitejS saitej

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

              p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by p3c0
              #6

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

              157

              saitejS 1 Reply Last reply
              0
              • p3c0P p3c0

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

                saitejS Offline
                saitejS Offline
                saitej
                wrote on last edited by
                #7

                @p3c0

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

                RokeJulianLockhartR 1 Reply Last reply
                1
                • saitejS saitej

                  @p3c0

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

                  RokeJulianLockhartR Offline
                  RokeJulianLockhartR Offline
                  RokeJulianLockhart
                  wrote on last edited by RokeJulianLockhart
                  #8

                  Is there something similar to QDockWidgets in QML?

                  @saitej, not to my knowledge. Per post/830426, stackoverflow.com/a/72717739's thread indicates that either one must utilise an external library, or reimplement it themselves.

                  When using a forum, remember to tag the person you are responding to, in case they are not subscribed to the thread.

                  1 Reply Last reply
                  0

                  • Login

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