How to Efficiently Draw a QImage to a Window.
-
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.
-
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(); }
-
Do you need some kind of graph ?
-
Is there some kind of history for these shapes are do you need to re-draw them all every time ?
-
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
-
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
-