PDA

View Full Version : Too Much RAM used by QGraphicsScene



grabalon
3rd May 2010, 17:46
Hey All,

I'm trying to create a mosaic of several big .png images
The images are arranged in a long ribbon, and I garuntee that no more than 5 are visible at a time.
I need to use a lot of the functionality of a QGraphicsScene, and QGraphicsView (zooming, adding annotation, drawing), so doing this in a QWidgit would be quite difficult.

The problem I have is RAM usage. When all the images load, I consume more memory than is allowable.

What I want to do is build functionality into my already existing Sub-class of QGraphicsItem, allowing images to be cleared from RAM when they are sufficiently out of the viewing window, and have them loaded again when they are needed.

-I cannot find any simple way to tell where the viewing window is when I am using ScrollHandDrag drag mode.
-I cannot find any simple way to clear images from RAM temporarily.

-I can maintain the location and size of my QGraphicsItem without depending on QPixmap geometry

Can anyone give me any hints what I can do to accomplish these goals?

grabalon
6th May 2010, 01:02
Ok, I've figured out how to delete the major components from my sub-classed QGraphicsItems. Now I just need a way to tell when they are no longer in the viewport of my QGraphicsView. I have looked all over for a signal that is emitted when the viewport moves, and it seems that there is not one.

Any help would be appreciated.

SixDegrees
6th May 2010, 01:22
You'll probably have to intercept one of the event handlers; there are a number in QAbstractScrollArea that sound like they might be useful.

grabalon
6th May 2010, 15:30
That was what I needed,

Solution:
override QAbstractScrollArea::paintEvent

Thanks

wysota
6th May 2010, 15:38
I would do it differently. I would have a QPixmapCache that was able to hold some amount of images. Then I would have my own class for representing items. Painting routine of the item class would grab the contents of the image from the cache instead of its own member variable. The cache would be responsible for getting rid of least recently used items. If a required item was missing in the cache, it could then be loaded back from disk. This way everything would work on its own without the need of deleting and creating items all the time.