[PyQt] QGraphicsView to display a png

David Boddie david at boddie.org.uk
Tue Jul 24 00:13:07 BST 2007


On Mon Jul 23 23:55:57 BST 2007, kib2 wrote:

> Thanks for your hints,
> 
> in fact the problem has been solved yesterday...
> My scene was refering to nothing at all, add a "self" like this :
> 
> scene = QtGui.QGraphicsScene(self)
> 
> and the image appears.

Ah, it seems that you were setting up the scene from with a method of
a class. Your problem was that, when the method returned, the scene
was garbage collected. Giving it a parent of "self" keeps it alive
thanks to Qt's parent-child object management. Alternatively, you
could have stored the scene in the instance of your class; in other
words, use self.scene instead.

> Now, Dave just told me it was a bad idea to put an image on a 
> QGraphicsView. I've already done it inside a Label, but I've no controls 
> on it. He suggested I've to write my own widget (from Qlabel or QWidget) 
> for that, but I don't see why it's a bad design decision.

Well, I guess that was in some private e-mail. It really depends on what
you are going to do with the image, and whether you need to use QGraphicsView
to show it.

> David : thanks again for your good work on the wiki.

You're welcome. I notice that you have added a link to your hints and tips
page. Thanks for doing that. In case you were unaware, there's an entire
French speaking Qt community online at

  http://www.qtfr.org/

Maybe some of the people there can speak Python, too. ;-)

David


More information about the PyQt mailing list