2

i have a GUI program built on PyQt, the GUI has a QtGraphicsView widget, which has a GraphicsScene, which has a Pixmap item to be displayed and updated, for instance, I use the following line to do this

view.scene().items().setPixmap(QPixmap.fromImage(qimage))   

Everytime, i modify the qimage and call this line to update the image display, and it worked well. later i want to add a loop to update the image continuously:

for i in xrange(10):
    qimage = .... #make some changes to qimage
    view.scene().items().setPixmap(QPixmap.fromImage(qimage))  

well,the image does not get updated within the loop. the viewport only display the first image(i=0) and the last image(i = 9), i thought it was because the ViewportUpate option of the GraphicsView widget, but it still does not work after i use:setViewportUpdateMode(QGraphicsView.FullViewportUpdate)... Any idea? Really thanks for the help!

shelper
  • 10,053
  • 8
  • 41
  • 67
  • its probably because it sends a notify event that something changed...however it does not have a chance to handle the update event since you are in a loop ... maybe look at using a timer class to call the code instead of a loop ... – Joran Beasley Sep 20 '12 at 18:44
  • maybe try adding `view.scene().update()` – Joran Beasley Sep 20 '12 at 18:49
  • @JoranBeasley i tried to add `time.sleep(1)` after setPixmap, but still no update, i also tried to add `view.scene().update()`, but still no update... – shelper Sep 20 '12 at 19:03

1 Answers1

5

Well, i think i found the issue i have to add one more lineQApplication.processEvents() to the loop otherwise the loop will occupy the processing time and gives the program no chance to update

for i in xrange(10):
    qimage = .... #make some changes to qimage
    view.scene().items().setPixmap(QPixmap.fromImage(qimage))  
    QApplication.processEvents()

now it works. anyway, thanks to all!

shelper
  • 10,053
  • 8
  • 41
  • 67