View Full Version : Optimizing redrawing in the scene

28th November 2007, 10:31

I have created a lot of items in the scene. I also have a rectangle(QGraphicsREctItem) moving with the cursor. Whenever the rectangle moves on the items, memory usage reaches 100%, and it moves slowly, when I move the rectangle from items, it works fine. It looks as if the items were redrawn everytime the rect changes pos and intersects with them. I need the same performence while moving the rect on that items as when I have only a cursor(nothing is redrawn then). How to do that? Maybe I should create that (zooming) directly on the viewport and that map view -> scene coordinates/

Any ideas appreciated.



28th November 2007, 17:50
The performance loss is caused by the fact that the item index needs to be rebuilt. You might want to disable indexing while you move items, if you don't need collision detection. See QGraphicsScene::setItemIndexMethod() and the respective property.

28th November 2007, 17:55
I already have this:

this->setItemIndexMethod(QGraphicsScene::NoIndex); in the constructor of my scene.

28th November 2007, 17:58
In that case try avoiding collision detection and cache items. Andreas has recently posted an article about it @ labs.

Edit: Or lose the rect...

28th November 2007, 18:00
ok. will do so and reply later.
I suppose I need to pop in to lab.trolltech sometimes.