PDA

View Full Version : QGraphicsView, OpenGL and repainting/updating



Amargedon
14th January 2009, 09:25
Hello,

I have a large program. In the past I used Qt3 and a canvas to draw on, on the background a pixmap (or multiple as tiles) and a few thousend lines which could change state (color).

I moved to Qt4 and changed the canvas to QGraphicsScene and QGraphicsView. I also wanted to get rid of the backgroundpixmap because the quality was ugly when zooming. I use now svg-tiles on a QtGLWidget which zooms very fast and is very nice. The lines are normal QGraphicsLineItems and they can change there color.

My problem: when the lines change color my CPU usage is about 90%. When a change the QtGLWidget to a QWidget the CPU usage is around 5%. I discoverd that the problem is within the paintEvent. On a QWidget it uses a boundingrect update (and updates only whats changed), but on a QGLWidget it uses a fullviewportupdate and so it renders al the items (few thousand and the background svg).

I tried to optimize this by using a sort of boundingrectupdate, but what I get is flickering because only a small part of the opengl buffer is filled. I also tried to cache the background, but the rendering into a pixmap was very slow and the overall performance wasn't better.

What I think is that it can help to draw all the lines with openglstatements in there paint function? Or mayby caching into a QImage and then only draw what's changed?

Do you have other suggestions?

Amargedon
19th January 2009, 10:38
Nobody an idea or suggestion?

^NyAw^
19th January 2009, 13:03
Hi,

I think that the problem is the overpainting. You have a OpenGL Widget and you overpaint with QPainter.

Try drawing lines using OpenGL instructions.