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)
Windows 7x64
Visual Studio 2010Does 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)?
-
Hey,
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.
-
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.