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. [solved]QML inside a QGraphicsView

[solved]QML inside a QGraphicsView

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

    Hello, I m using QGraphicsView / QGraphicsScene to design a game.
    I want to use QML to design the menu. How Can I add my QML code on the top of my GraphicsView ?

    Nothing in Biology Makes Sense Except in the Light of Evolution

    1 Reply Last reply
    0
    • M Offline
      M Offline
      minimoog77
      wrote on last edited by
      #2

      From docs:

      @QDeclarativeEngine engine;
      QDeclarativeComponent component(&engine);
      component.setData("import QtQuick 1.0\nText { text: "Hello world!" }", QUrl());
      QDeclarativeItem *item = qobject_cast<QDeclarativeItem *>(component.create());

      //add item to view, etc@

      Since QDeclarativeItem is QGraphicsObject you can add to your QGraphicsScene.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dridk
        wrote on last edited by
        #3

        thanks! It's cute like Qt!:)

        Nothing in Biology Makes Sense Except in the Light of Evolution

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dridk
          wrote on last edited by
          #4

          Warning! After some try, I get some crash using QFile and setData.
          So do not do :
          @
          QFile file("main.qml"); {..}
          component.setData(file.readAll(), QUrl());@

          And prefer :

          @ mComponent = new QDeclarativeComponent(mEngine, QUrl::fromLocalFile("main.qml"));
          @

          Nothing in Biology Makes Sense Except in the Light of Evolution

          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