Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Painting polylines with Pen width 2 is almost 100(!) times slower
I am drawing polylines with a few thousand points within a GraphicsScene. In one case, I use a default cosmetic pen, in the other a cosmetic pen of width 2.
I knew that drawing with a wider pen adds some complexity and hence would be slower, but I never expected this.
For default pen width, drawing the polyline on average takes 2.3 ms.
For width 2, it comes to a whopping 212 ms.
Qt: 4.8.1 (but I understand nothing much has changed in this area since then)
Visual Studio 2010
Does anyone have an explanation for why the difference is this extreme? Any suggestions what I could try to get the times down (apart from sticking to the line pen)?
monkeyDancer last edited by
just a guess. Try to deactivate QPainter::Antialiasing.
Antialising will need extra calculations for making lines look smoother. The color of a pixel is influenced by the surrounding pixels.
More surrounding pixels => more calculations. Just a guess as i said.
kenchan last edited by
Do different cap and join styles types make any difference to the performance?
Antialiasing is off.
Join style does make a difference. The factor 100 is the best result I got.
One solution I since learned about is using OpenGL as render engine.
Just call setViewport(new QOGLWidget) on the GraphicsView.
Might introduce some unintended changes, but looks promising as far as polyline drawing is concerned.