[PyQt] QGraphicsView to display a png

David Boddie david at boddie.org.uk
Mon Jul 23 23:37:16 BST 2007


On Mon Jul 23 23:06:34 BST 2007, Adam Tenderholt wrote:

> I think you are drawing your pixmap off the edge of the scene. Try the
> following:
> 
> scene = QtGui.QGraphicsScene()
> 
> #scene.setSceneRect(-600,-600, 600,600)
> scene.setSceneRect(-600, -600, 1200, 1200)
> 
> pic = QtGui.QPixmap(":/images/triangle.png")
> scene.addItem(QtGui.QGraphicsPixmapItem(pic))
> view = self.gv
> view.setScene(scene)
> view.setRenderHint(QtGui.QPainter.Antialiasing)
> view.show()

That might fix the problem. Another question worth asking is: have the
resources been set up correctly? The assignment,

  pic = QtGui.QPixmap(":/images/triangle.png")

refers to an image in a resource that is usually stored in a module
and imported somewhere in an application before it is used. The image
may reside in images/triangle.png but the original poster needs to
create a .qrc file that lists it, run pyrcc4 on the .qrc file to
generate a Python module, and import that to make it work.

Some of the examples included with PyQt4 use .qrc files to package
images and other resources as Python modules, so there should be
plenty of examples worth looking at.

David


More information about the PyQt mailing list