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. What Qt type is best for graphics and image drawing?
Forum Updated to NodeBB v4.3 + New Features

What Qt type is best for graphics and image drawing?

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 2 Posters 1.3k Views 1 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.
  • johnratiusJ Offline
    johnratiusJ Offline
    johnratius
    wrote on last edited by
    #1

    I am wanting to make a "limitless" surface or grid, and am wondering what type of Qt type to use. I thought of QGraphicsScene, but I'm not sure if I can draw OpenGl-like objects (thinking of lines and rectangles, to draw a grid pattern) with graphics scene. I know I have more drawing capabilities with QPainter, but I am going to be having several hundred different types of objects that lay on the grid, each will have a large amount of properties. I will most likely be drawing them as images, but am not sure about the grid part.
    What's the best way to do this in Qt?

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

      Hi
      QGraphicsScene/view allows zoom and pan and other features out of the box
      and you can draw anything you like as you can
      inherit QGraphicsItem and use QPainter to draw the actual shape.

      So if you need zooming / panning / selection / interaction / Level of Detail support and such
      features, its a good way to go to use QGraphicsScene.

      But if such features is not needed, then a pure QPainter might be better in terms of simplicity.

      1 Reply Last reply
      2
      • johnratiusJ Offline
        johnratiusJ Offline
        johnratius
        wrote on last edited by
        #3

        I will definitely use Panning and Zooming features. I wasn't aware you could use QPainter inside it. I guess I will be using QGraphicsScene. Though, do I have to have a QGraphicsView with the QGraphicsScene?

        mrjjM 1 Reply Last reply
        0
        • johnratiusJ johnratius

          I will definitely use Panning and Zooming features. I wasn't aware you could use QPainter inside it. I guess I will be using QGraphicsScene. Though, do I have to have a QGraphicsView with the QGraphicsScene?

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          @johnratius
          Hi
          Ok then Graphics View Framework should be the best way :)
          Yes the view draws the items the scene holds. you can have multiple views on to same scene etc.
          So you need the view as that is the Visual part.

          Make sure to read about the coordinate system as that is more complex than simple
          x,y pixel values from a normal drawing api.
          https://doc.qt.io/qt-5/graphicsview.html

          1 Reply Last reply
          2
          • johnratiusJ Offline
            johnratiusJ Offline
            johnratius
            wrote on last edited by johnratius
            #5

            Thanks, is there an example of QGraphicsScene and QGraphicsView that implements the grid or zoom and panning feature?

            Even better, a grid-like example? I want a "infinite" like grid, and am not sure if I should just draw lots of QRects or lines performance wise.

            mrjjM 1 Reply Last reply
            0
            • johnratiusJ johnratius

              Thanks, is there an example of QGraphicsScene and QGraphicsView that implements the grid or zoom and panning feature?

              Even better, a grid-like example? I want a "infinite" like grid, and am not sure if I should just draw lots of QRects or lines performance wise.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @johnratius
              Hi
              Check out
              https://doc.qt.io/qt-5/qtwidgets-graphicsview-chip-example.html
              It takes each pixel from an image an make an item out of it :)
              That is sort of a grid.

              But im not really sure what a "limitless" surface or grid would be ?
              Do you have an image of such concept ?

              johnratiusJ 1 Reply Last reply
              0
              • mrjjM mrjj

                @johnratius
                Hi
                Check out
                https://doc.qt.io/qt-5/qtwidgets-graphicsview-chip-example.html
                It takes each pixel from an image an make an item out of it :)
                That is sort of a grid.

                But im not really sure what a "limitless" surface or grid would be ?
                Do you have an image of such concept ?

                johnratiusJ Offline
                johnratiusJ Offline
                johnratius
                wrote on last edited by johnratius
                #7

                @mrjj
                Thanks, I'll check it out. Yes, the user can drag the grid wherever, and it will appear that it is endless. I was planning on drawing each cell from the top left to bottom right, and then translate all of them once the panning reaches -1 or +1 unit on x or y axis back, so it appears the grid keeps going. If that makes sense. Zooming will have to increase the number of drawn cells though. Is this ideal for performance?

                mrjjM 1 Reply Last reply
                0
                • johnratiusJ johnratius

                  @mrjj
                  Thanks, I'll check it out. Yes, the user can drag the grid wherever, and it will appear that it is endless. I was planning on drawing each cell from the top left to bottom right, and then translate all of them once the panning reaches -1 or +1 unit on x or y axis back, so it appears the grid keeps going. If that makes sense. Zooming will have to increase the number of drawn cells though. Is this ideal for performance?

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @johnratius
                  Yes makes perfect sense. You can also use the LOD feature (if possible with your drawings) to
                  allow a huge number of objects shown at same time. (100K or more without any issue)
                  depending on the PC.

                  1 Reply Last reply
                  0
                  • johnratiusJ Offline
                    johnratiusJ Offline
                    johnratius
                    wrote on last edited by
                    #9

                    What is the LOD feature? I will probably try to use it.

                    mrjjM 1 Reply Last reply
                    0
                    • johnratiusJ johnratius

                      What is the LOD feature? I will probably try to use it.

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @johnratius

                      Hi
                      LOD means Level of Detail and its often used in games where an object that is far away from view, is drawn using a lesser detailed model then when up close.

                      for Graphics View Framework
                      its more like a "factor" that allows you do reduce the drawing
                      calls. Like not paint small text or what else that could make sense for your type of shapes.

                      from the 40000 sample. Here is only draws the rect when far away and not all the small details.

                        const qreal lod = option->levelOfDetailFromTransform(painter->worldTransform());
                          if (lod < 0.2) {
                              if (lod < 0.125) {
                                  painter->fillRect(QRectF(0, 0, 110, 70), fillColor);
                                  return;
                              }
                      
                      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