[PyQt] QGraphicsScene background

Hans-Peter Jansen hpj at urpla.net
Sat Jul 23 00:04:17 BST 2011


On Friday 22 July 2011, 21:04:44 Lee Harr wrote:
> 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!

Did you checked the navigation pad example? It uses some tricks, e.g. by 
(optionally) using OpenGL and various transformations, that might be 
helpful for your issue, too.

Pete


More information about the PyQt mailing list