[PyQt] "Image view" problem

Phil Thompson phil at riverbankcomputing.com
Thu Feb 28 13:27:14 GMT 2008


On Thursday 28 February 2008, Enis Karaarslan wrote:
> Hello all,
>
> I want to show a graph (png file) about network traffic usage in my pyQt
> application. The following works, but I want to put the picture in the main
> window.
>
> image = Image.open ('ragraph.png')
> image.show()
>
>
> A simple question I guess, but as a newbie - I couldn't suceed.
> I put a graphicsView object but I couldn't write to it.
>
> 		self.image = QtGui.QImage()
> 		self.image.load(QtCore.QString("ragraph.png"))
> 		self.image=self.image.scaledToWidth(self.image.width()/2)
>
> 		#self.image=self.image.scaled (QSize(321, 271) )
>
>
> 		scene = QtGui.QGraphicsScene()
> 		self.item = self.image
> 		scene.addItem(self.item)
> 		scene.setSceneRect(-600, -600, 1200, 1200)
>
> 		self.graphicsView.show();
>
> I couldn't additem to the QGraphicsScene object
> I suppose I am in a wrong direction. Any recommendations will be
> appreciated.
>
> Thanks,

Do you need to use QGraphicsView? The simplest way to display an image is to 
display a QPixmap in a QLabel...

label = QLabel()
label.setPixmap(QPixmap("ragraph.png"))
label.show()

Phil


More information about the PyQt mailing list