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 ?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With