I have a QGraphicsScene with a custom graphics item that can have a very compute-intensive paint() method, depending on the number of points in the data it is fed (basically, it is drawing a number of lines, where the count can get to 7 or 8 million). I tried creating a QPainterPath / QGraphicsPathItem, but I run out of memory with paths of millions of lines. So, I was forced to implement the paint() method.

The problem is, that when I try to use a QRubberBand-derived class to zoom in or otherwise interact with the scene, I get a paint event on the item for every mouse event. For an item that must draw 8 million lines, this is a non-starter, and makes zooming impossible.

I have read other posts which talk about the use of pixmaps to grab widget contents during zoom operations. QGraphicsItem supports pixmap caching, and from the description, it seems that this would do what I want - once the item is initially drawn into the pixmap, subsequent painting is done from the pixmap instead of the paint() method.

In the constructor of my item, I added a call to setCacheMode( QGraphicsItem:eviceCoordinateCache ). As a result, my paint() method is never called. I have tried adding calls to update() in other places in the code where the item's contents are changed, but nothing ever happens. Comment out the setCacheMode() line in the constructor, everything is painted as usual.

So what is going on here? Are there some preconditions for the use of CacheMode?

Any examples? I've really been beating my head on the wall over this one.