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. How to Efficiently Draw a QImage to a Window.
QtWS25 Last Chance

How to Efficiently Draw a QImage to a Window.

Scheduled Pinned Locked Moved Unsolved General and Desktop
qimagedraw
19 Posts 3 Posters 13.6k 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.
  • S Offline
    S Offline
    SGaist
    Lifetime Qt Champion
    wrote on 21 Feb 2016, 22:37 last edited by
    #10

    Is your application painting static content ? If so, then don't trigger update that much, there's no real need.

    paintEvent will be called when needed so with your last sample, calling update every 50ms is useless and power consuming.

    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
    • A Offline
      A Offline
      as2388
      wrote on 21 Feb 2016, 22:41 last edited by
      #11

      Ok, so that may not have been a great example. In reality it will be dynamic content, so I really do need a frequent screen refresh. This is a slightly more representative example:

      int x = 0;
      void MainWindow::paintEvent(QPaintEvent *event) {
          if (x > 500) x = 0;
          QPainter painter(this);
          painter.drawLine(QPointF(10, 10), QPointF(x++, x++));
          painter.end();
      }
      
      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 21 Feb 2016, 23:03 last edited by
        #12

        Do you need some kind of graph ?

        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
        • A Offline
          A Offline
          as2388
          wrote on 22 Feb 2016, 00:05 last edited by
          #13

          No, it's arbitrary shapes.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 22 Feb 2016, 09:46 last edited by
            #14

            Is there some kind of history for these shapes are do you need to re-draw them all every time ?

            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
            • A Offline
              A Offline
              as2388
              wrote on 22 Feb 2016, 14:07 last edited by
              #15

              Need to redraw.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 22 Feb 2016, 22:11 last edited by
                #16

                The first thing I'd do is optimize the data sent e.g. do you really need to build a line of 500 points if you already know the final coordinates ?

                Otherwise, maybe consider using OpenGL

                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
                • A Offline
                  A Offline
                  as2388
                  wrote on 23 Feb 2016, 23:42 last edited by
                  #17

                  So to confirm: there's no way to draw in Qt without invoking the relatively expensive update() first?

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 24 Feb 2016, 13:12 last edited by
                    #18

                    Yes there is, do the drawing in another thread on a QImage and then trigger the update with that image. You have an example of this in the Mandelbrot example

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

                    K 1 Reply Last reply 24 Feb 2016, 18:52
                    0
                    • S SGaist
                      24 Feb 2016, 13:12

                      Yes there is, do the drawing in another thread on a QImage and then trigger the update with that image. You have an example of this in the Mandelbrot example

                      K Offline
                      K Offline
                      kshegunov
                      Moderators
                      wrote on 24 Feb 2016, 18:52 last edited by
                      #19

                      @as2388

                      Yes there is, do the drawing in another thread on a QImage and then trigger the update with that image.

                      I'd add to @SGaist's great point - even convert the image to a QPixmap in the worker (after drawing it), and in the paint event just splat it onto the widget.

                      Read and abide by the Qt Code of Conduct

                      1 Reply Last reply
                      0

                      19/19

                      24 Feb 2016, 18:52

                      • Login

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