Results 1 to 4 of 4

Thread: QGraphicsScene with many Items requires too much memory

  1. #1
    Join Date
    Nov 2012
    Posts
    22
    Thanks
    1

    Default QGraphicsScene with many Items requires too much memory

    Hi everyone,

    I'm using a custom (inherited) QGraphicsScene to visualize a large number of 2D items. The items are custom QGraphicsLineItems with a level-of-detail threshold to paint them only at certain zoom levels. There are quite alot of them (>>500k) and they use up much more memory than I would like.
    Two things came to mind that might prevent this:

    1. Many of the lines are exactly the same except for their position. Is it maybe possible to somehow create only one object for a subset of lines and draw it at multiple positions in the scene?!

    2. I keep only those object in memory that are actually shown to the user. Where would I implement this deleting of items that moved out of view and adding of items that are newly visible, i.e. which method of QGraphicsScene should I overload for this? Won't adding items right before a scene is updated (using addItem) in turn trigger more updates?

    Both approaches do not seem very appealing so if you can think of something simpler/better please tell.

    Background: The widget I'm talking about is a timeline with vertical lines at the positions of hours, minutes, seconds and frames. The lines for frames are only made visible when the view is sufficiently zoomed into the scene. The widget is supposed to support >=30fps and videos of more than 24 hours, thus the large number of line items. Is the approach of subclassing QGraphicsScene and using level-of-detail GraphicsItems even the right way to go on this?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsScene with many Items requires too much memory

    I would suggest to use QGraphicsScene::drawBackground() or QGraphicsScene::drawForeground() instead of those items.

    Or if you do need level of detail information, then QGraphicsView has those methods as well.
    Last edited by wysota; 22nd January 2013 at 17:41.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Nov 2012
    Posts
    22
    Thanks
    1

    Default Re: QGraphicsScene with many Items requires too much memory

    Thanks, QGraphicsScene::drawBackground() looks very much like what I wanted. I will check back once I tried it tomorrow.

  4. #4
    Join Date
    Nov 2012
    Posts
    22
    Thanks
    1

    Default Re: QGraphicsScene with many Items requires too much memory

    Alright, that did it. I would mark this as solved but the edit function seems to be hidden...
    Thanks for the help!

Similar Threads

  1. QGraphicsScene is SLOW with a lot of items !
    By pl01 in forum Qt Programming
    Replies: 11
    Last Post: 5th August 2011, 16:06
  2. How to add items in a QGraphicsScene?
    By schmimona in forum Qt Programming
    Replies: 2
    Last Post: 3rd August 2011, 08:53
  3. Most Memory-Efficient Way to Add Images to QGraphicsScene?
    By datek2517 in forum Qt Programming
    Replies: 3
    Last Post: 28th June 2011, 20:46
  4. QGraphicsScene - memory consumption
    By mateuszzz88 in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 29th November 2010, 20:39
  5. How could I save Items on a QGraphicsScene?
    By pinkfrog in forum Qt Programming
    Replies: 2
    Last Post: 9th January 2009, 05:03

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.