Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. What the fastest way to draw 2d graphic in qt?

What the fastest way to draw 2d graphic in qt?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
5 Posts 3 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.
  • ataryqA Offline
    ataryqA Offline
    ataryq
    wrote on last edited by
    #1

    What the fastest way to draw 2d graphic in qt? Where I can reading about it?
    Sorry for my bad English.

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

      Hi and welcome to devnet,

      It will depend on what you want to draw. Usually OpenGL is the fastest.

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

      ataryqA 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi and welcome to devnet,

        It will depend on what you want to draw. Usually OpenGL is the fastest.

        ataryqA Offline
        ataryqA Offline
        ataryq
        wrote on last edited by
        #3

        @SGaist
        Thanks. I want draw 2000 lines of different colors more than 25 time/second. What way the best for my target?

        1 Reply Last reply
        0
        • ProteosP Offline
          ProteosP Offline
          Proteos
          wrote on last edited by Proteos
          #4

          Hi,

          Please correct me if I'm wrong (thus, I will learn too).
          If you only want to draw lines, I'm not sure that using OpenGL is necessary, and its implementation and use can be quite tricky.

          Personnaly, I would go for a pure Qt approach :

          • Use a QTimer to call your drawing procedure at the frequency you need.
          • Draw your lines on a QImage with a loop. (QImage are optimised for direct access to pixels and are therefore made for drawing).
          • Make a QPixmap from this image (QPixmap are optimised for display).
          • Display you QPixmap in a widget. As far as I'm concerned, I use a QGraphicsScene to receive my QPixmap, and then I display it in a QGraphicsView (once again, I would be glad to learn a better way).

          For now, with the relative knowledge I have, nothing makes me think that OpenGL would be faster for 2D, because you would have pretty much the same procedure :

          • create your image on a matrix (apply a projection matrix to render it ? projection matrices are used in 3D to "flatten" the scene, but can we ignore them in 2D ? I don't know)
          • save the image on a backbuffer
          • swap the frontbuffer and the backbuffer
          • display it in an OpenGLWidget.

          The procedure is not shortened using OpenGL, so is there such a big optimization difference between Qt and OpenGL in the case of 2D drawing ?

          OpenGL is more complex than Qt, so I suggest that unless you absolutely need it, use Qt instead.
          Testing is the best way to know ! Try using Qt, and if the result is too slow, try using OpenGL (or should I say 'try to use OpenGL' ;-) ).

          ataryqA 1 Reply Last reply
          0
          • ProteosP Proteos

            Hi,

            Please correct me if I'm wrong (thus, I will learn too).
            If you only want to draw lines, I'm not sure that using OpenGL is necessary, and its implementation and use can be quite tricky.

            Personnaly, I would go for a pure Qt approach :

            • Use a QTimer to call your drawing procedure at the frequency you need.
            • Draw your lines on a QImage with a loop. (QImage are optimised for direct access to pixels and are therefore made for drawing).
            • Make a QPixmap from this image (QPixmap are optimised for display).
            • Display you QPixmap in a widget. As far as I'm concerned, I use a QGraphicsScene to receive my QPixmap, and then I display it in a QGraphicsView (once again, I would be glad to learn a better way).

            For now, with the relative knowledge I have, nothing makes me think that OpenGL would be faster for 2D, because you would have pretty much the same procedure :

            • create your image on a matrix (apply a projection matrix to render it ? projection matrices are used in 3D to "flatten" the scene, but can we ignore them in 2D ? I don't know)
            • save the image on a backbuffer
            • swap the frontbuffer and the backbuffer
            • display it in an OpenGLWidget.

            The procedure is not shortened using OpenGL, so is there such a big optimization difference between Qt and OpenGL in the case of 2D drawing ?

            OpenGL is more complex than Qt, so I suggest that unless you absolutely need it, use Qt instead.
            Testing is the best way to know ! Try using Qt, and if the result is too slow, try using OpenGL (or should I say 'try to use OpenGL' ;-) ).

            ataryqA Offline
            ataryqA Offline
            ataryq
            wrote on last edited by
            #5

            @Proteos Thanks very mach! It's very intresting! I will try it.

            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