[PyQt] QGraphicsScene background

Lee Harr missive at hotmail.com
Fri Jul 22 20:04:44 BST 2011


I work on a turtle graphics application written using
PyQt (pynguin.googlecode.com) and I am stuck on one
particular feature that I would like to add.

Right now, I am using QGraphicsScene and when the
turtle draws, it uses QGraphicsItem based objects to
show the results. Mostly QGraphicsPathItem,
QGraphicsEllipseItem and QGraphicsSimpleTextItem.

It works quite well, but in long-running programs
when many many items have been added, the scene
starts to slow down.


Two options I have looked at are:

Re-implementing drawBackground. I save a QPixmap as
self.bg in my QGraphicsScene subclass, then do
painter.drawPixmap(rect, self.bg, sourcerect)
in drawBackground. It works, but when the zoom
level is anything but 1:1 it gets very slow.

The other way was to add a QGraphicsPixmapItem as
the lowest item on the stack. That also seems like it
might work, but again, as soon as the zoom level is
anything but 1:1 the speed goes way down instantly.


What I think I want to be able to do is to take
all of those graphics items and flatten them down on
to the background and then delete those items.

Is there any way that an approach like this will
be able to speed up the application (including the
ability to zoom to arbitrary levels...)?


Any suggestions greatly appreciated!

 		 	   		  


More information about the PyQt mailing list