Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

qpainter painting alternatives (performance sucks on Mac)

I have a class which displays waveform data of audiofiles in a QWidget (see screenshot of the widget below, back then i still used a gradient, which caused poor performance).

The audio data is painted in the paintEvent directly on the widget using multiple calls to QPainter::drawLine (the minimum amount of calls to QWidget::drawLine is equivalent to the width of the widget => at least one line for each x coordinate). While the approach works quite well on Windows (a paintEvent in fullscreen takes around ~4ms), the performance is 4-5 times worse when the program is run under MacOS.

The performance of the painting is important for fluid scrolling of the displayed data.

So my question is, does anyone know a faster alternative to QPainter.drawLine to paint lines (platform dependant solutions might be ok, as long as they can be used in a paintEvent), or is there a way to speed up scrolling, some kind of buffering etc ?

old screenshot of the widget (still used gradients, which caused poor performance)

like image 475
smerlin Avatar asked May 22 '11 17:05

smerlin


1 Answers

The current version (4.7.x) of Qt uses Core Graphics backend for painting. It can be slow at times as you found out. On Windows, it uses a software renderer which has really good performances.

My suggestion is to not paint on the passed painter directly in your paint event. Instead, create a QImage the same size as your widget paint area and paint on it. This will use the software renderer which is much faster. Then plot the QImage onto the painter when needed.

like image 194
Stephen Chu Avatar answered Nov 15 '22 08:11

Stephen Chu