I have a short script that modifies an image with PIL several times. I would like to be able to display the intermediate steps as it finishes with them, so I added a QGraphics Scene and I am trying to display the stages there. It will properly size and center the final stage (the last one posted before exiting the function), but it displays the intermediate steps without sizing or centering them.
The code to post the image is:
#Code to generate the image and create the loop here...
imgQ = ImageQt.ImageQt(img)
pixMap = QtGui.QPixmap.fromImage(imgQ)
scene = QtGui.QGraphicsScene()
self.ui.previewGv.setScene(scene)
pixMap = pixMap.scaled(self.ui.previewGv.size())
#scene.clear()
scene.addPixmap(pixMap)
self.ui.previewGv.repaint()
self.ui.previewGv.show()
Is there some way to get it to properly display each stage?
It is hard to determine your problem without loop code and working example. But i have similar test application, hope it will help.
The main points:
If you are doing some processing or
sleep
in loop, you need to callQCoreApplication.processEvents()
to allow Qt to do updates.I'm saving reference to
ImageQt.ImageQt
(self.imgQ
) or it will crash.As I understood, you are creating
QGraphicsScene
in each iteration, better solution to create it once and then callscene.clear()
.Scaling pixmap just to display it sized and centered is expensive,
QGraphicsView.fitInView()
maked for this purpose.