Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Forum Updated on Feb 6th

    Unsolved Qml in Qdockwidget

    General and Desktop
    3
    7
    4747
    Loading More Posts
    • 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.
    • saitej
      saitej last edited by 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 ?

      p3c0 1 Reply Last reply Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        @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 Reply Quote 1
        • p3c0
          p3c0 Moderators @saitej last edited by

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

          157

          saitej 2 Replies Last reply Reply Quote 2
          • saitej
            saitej @p3c0 last edited by

            @p3c0
            Thanks !!

            1 Reply Last reply Reply Quote 0
            • saitej
              saitej @p3c0 last edited by 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.

              p3c0 1 Reply Last reply Reply Quote 0
              • p3c0
                p3c0 Moderators @saitej last edited by 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.

                157

                saitej 1 Reply Last reply Reply Quote 0
                • saitej
                  saitej @p3c0 last edited by

                  @p3c0

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

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post