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. Rendering QGraphicsScene into QML scene texture

Rendering QGraphicsScene into QML scene texture

Scheduled Pinned Locked Moved Solved QML and Qt Quick
11 Posts 2 Posters 4.3k 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.
  • SeeLookS Offline
    SeeLookS Offline
    SeeLook
    wrote on last edited by SeeLook
    #1

    Hi All,
    Happy New Year!

    There was a post about integration QGraphicsView into newer QtQuick
    (or rather about lack of the integration and necessity of migration):
    https://forum.qt.io/topic/62637/how-to-integrate-qgraphicsview-with-qml
    There are mentioned 4 ways how to migrate from QGraphicsView to QtQuick

    but I've just discovered another one: to render QGraphicsScene into QML texture.
    It is "widely" used by Qt Chart module:
    https://github.com/qt/qtcharts/blob/dev/src/chartsqml2/declarativechart.cpp
    (starts from line 584)
    but this is only example I found.

    Could someone describe it more. Some general concept of that.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      The general concept is that the scene is rendered in a QImage that is then converted to a texture to be used by the node.

      See the renderScene and updatePaintNode functions.

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • SeeLookS Offline
        SeeLookS Offline
        SeeLook
        wrote on last edited by
        #3

        @SGaist thanks for the answer.

        I'm asking because I have already implemented a complex scene with many elements (font glyphs, lines), let's say similar to linear chart with a few series of data.
        Porting it to QML canvas seems to be heavy job and using javascript to manage logic rather has performance impact whether I have logic already written in C++.
        Because managing those elements requires operating on flat pane coordinates, using other techniques mentioned in above post (QML native elements or reimplementing QQuickItem or QQuicaPainted item) seems to be not my case.

        But please correct me if I'm wrong.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          I'm not sure I'm following you. From what you described, following the technique of the DeclarativeChart class will likely be the simple road since you have everything already working with a QGraphicsScene.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • SeeLookS Offline
            SeeLookS Offline
            SeeLook
            wrote on last edited by
            #5

            I would like to migrate from QtWidgets to QML, so I'm looking for the best choice how to do this with part of my app which lays upon QGraphicsScene.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Then,, AFAIK, without reimplementing everything, the QQuickItem way will likely be the simplest.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1
              • SeeLookS Offline
                SeeLookS Offline
                SeeLook
                wrote on last edited by
                #7

                Do You mean this one with rendering QImage into texture?

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  You don't render the QImage to a texture, your render your scene on a QImage and then you make a texture of it. Qt already supports creating texture from QImage.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • SeeLookS Offline
                    SeeLookS Offline
                    SeeLook
                    wrote on last edited by
                    #9

                    Ok, I understood a point but I'm mixing terminology...
                    Thank You a lot for the answer.

                    1 Reply Last reply
                    0
                    • SeeLookS Offline
                      SeeLookS Offline
                      SeeLook
                      wrote on last edited by
                      #10

                      I tested it with different options what brought me to following:
                      Using QQuickPaintedItem and painting scene content (or its part) in overloaded paint() method gives the same effects like rendering to QImage and using it as a texture.
                      But when QQuickPaintedItem has set:

                      setRenderTarget(QQuickPaintedItem::FramebufferObject);
                      

                      to drawing directly using GL paint engine- it is much faster (2-3 times)
                      so:

                      void MyQuickPaintedItem::paint(QPainter* painter) {
                        graphicsScene->render(painter, boundingRect(), boundingRect());
                      }
                      

                      Does its job well

                      1 Reply Last reply
                      1
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        Great !

                        Thanks for the feedback.

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        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