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

Show Qml file in QGraphicsView

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 2.1k Views 2 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.
  • M Offline
    M Offline
    MajidKamali
    wrote on last edited by
    #1

    Hi.
    I have a QGraphicsView and I want to add a qml file in it as part of scene.
    I used following code but nothing is shown in scene, just a gray rectangle

    QQuickView *view = new QQuickView;
    view->setSource(QUrl("qrc:/qml/SettingsButton.qml"));
    
    QWidget *container = QWidget::createWindowContainer(view);
    container->setMinimumSize(150, 50);
    
    QGraphicsProxyWidget * item = scene->addWidget(/*(QWidget *)*/container);
    

    What's wrong with this code?

    SettingsButton.qml has an Item as root and some rectangles and images.

    Thanks

    p3c0P 1 Reply Last reply
    0
    • M MajidKamali

      Hi.
      I have a QGraphicsView and I want to add a qml file in it as part of scene.
      I used following code but nothing is shown in scene, just a gray rectangle

      QQuickView *view = new QQuickView;
      view->setSource(QUrl("qrc:/qml/SettingsButton.qml"));
      
      QWidget *container = QWidget::createWindowContainer(view);
      container->setMinimumSize(150, 50);
      
      QGraphicsProxyWidget * item = scene->addWidget(/*(QWidget *)*/container);
      

      What's wrong with this code?

      SettingsButton.qml has an Item as root and some rectangles and images.

      Thanks

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

      @MajidKamali QGraphics* classes only work with QtQuick 1.x.

      157

      M 1 Reply Last reply
      0
      • p3c0P p3c0

        @MajidKamali QGraphics* classes only work with QtQuick 1.x.

        M Offline
        M Offline
        MajidKamali
        wrote on last edited by
        #3

        @p3c0 so how can I embed qml file in qgraphics framework?

        p3c0P 1 Reply Last reply
        0
        • M MajidKamali

          @p3c0 so how can I embed qml file in qgraphics framework?

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

          @MajidKamali Use QQuickWidget to load the QML and since QQuickWidget inherits QWidget you can use QGraphicsProxyWidget to embed it.

          157

          1 Reply Last reply
          1

          • Login

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