PDA

View Full Version : Resizing QGraphicsView / Repainting QGraphicsItem



SixDegrees
21st May 2010, 21:49
I have an application containing a QGraphicsView, which in turn views a QGraphicsScene containing a single customized QGraphicsItem. When the user resizes the application's main window, the QGraphicsView, of course, gets resized as well. When this happens, we would like the QGraphicsItem to repaint itself. It already does this, of course.

The problem is that repainting is inherently slow, involving database lookups and a fair amount of computation before the QGraphicsItem can proceed with painting, a process which can take a few seconds to complete.

So the problem is: when the QGraphicsView resizes, it sends a steady stream of repaint events down to the QGraphicsItem. This causes an abominable delay while the QGraphicsItem attempts to process all of them.

There are many solutions to this problem, but what I'd like to is only propagate resize events when the user lets go of the mouse and the window/QGraphicsView/QGraphicsItem are all at their final size, and only then go through the slow repaint calls. Note that mouseRelease events will take place outside the QGraphicsView, when the user is resizing the main application window.

What is the best way to accomplish this?

jryannel
22nd May 2010, 08:24
Not sure if this works ;-) First of all graphicsview viewport updates are controlled by QGraphicsView::ViewportUpdateMode. Not sure if a set to QGraphicsView::NoViewportUpdate will also prevent updates when resizing. That's one part.

The other part should be hopefully in QGraphicsView::resizeEvent (or sublcass), where probably a call to update is done to redraw the view. This is something you want to prevent it resize events come in quickly.

So best maybe is to derive from QGraphicsView and override resizeEvent. There you might want to use QTime, especially the elapsed() method to check if the ui came to rest. If the ui came to rest, you need to call QGraphicsView::reszizeEvent(...)

Haven't tried it but sounds at least at something you may want to try out ;-) If it works, please post your solution. Thanks