Sushruth Siv
Sushruth Siv

Reputation: 45

How to change image in QGraphicsView in PyQT?

I am able show an image initially when the form loads. How can I change the image later with another class.

Main class:

self.scene = QtGui.QGraphicsScene()
self.graphicsView = QtGui.QGraphicsView(Form)
self.graphicsView.setGeometry(QtCore.QRect(10, 280, 681, 331))
self.graphicsView.setObjectName(_fromUtf8("graphicsView"))
self.scene.addPixmap(QtGui.QPixmap(search_result)) 
self.graphicsView.setScene(ui.scene)

another class:

ui.graphicsView.resetCachedContent()
ui.scene.addPixmap(QtGui.QPixmap('path to another file')) 
ui.graphicsView.setScene(ui.scene)

Upvotes: 1

Views: 5407

Answers (1)

Sudhanshu Mishra
Sudhanshu Mishra

Reputation: 2094

jpg images can't be displayed in QGraphicsView. use QLabel to show jpg images

Upvotes: 2

Related Questions