Qt World Summit: Submit your Presentation

How to disable drawing of QGraphicsItems

  • So I have a couple thousand QGraphicsItem objects being added to the scene and being drawn. All items are updated and added to the scene every 10 sec or so and this seems to cause a significant lag of up to 5 seconds on my GUI. I have searched all over the internet to find ways to improve performance including trying to set no indexing method to the scene, caching . I also tried grouping some of the items into a QGraphicsItemGroup because every update actually creates a few interrelated items and so it would make sense to just group them together so they are treated as one. This didn't actually help with the performance however. I'm now thinking of disabling any updates to the QGraphicsView that come from my QGraphicsScene but it doesn't seem very clear how you can do that because all I see is something called updatesEnabled() which will disable drawing on the entire QGraphicsView but I only want to disable drawing of certain items in the QGraphicsScene object and then resume the drawing when I want to later. The idea is to delay the drawing of my items on the view until all the thousands of items are updated and added to the scene. Any ideas on what I could try?

  • I guess one way to do this would be to call setData on my items in the scene and add some meaningful tag to the items like some string to identify them and hide my items so they don't update and then when I want to resume updates( calling update on all items at one time) , I call items() in the scene, find the items I want to update and call update() on each item manually... any ideas on if I should expect a performance improvement in doing things this way?

Log in to reply