3
votes

According to Qt Documentation, " void QGraphicsItem::update ( const QRectF & rect = QRectF() ) " does not cause an immediate paint; instead it schedules a paint request that is processed by QGraphicsView after control reaches the event loop. Here is my code:

this->item->setPixmap( QPixmap::fromImage(*coloration->image) );// QGraphicsPixmapItem 
this->item->update();
this->scene->update(); // QGraphicsScene
this->view->update(); // QGraphicsView

and the code is in a method that will be invoked every 100 milliseconds(and in which the coloration->image will change), but the Qt refuses to update the image every 100 milliseconds, and it only renders the final image. So, how could I paint the item immediately?

2
Did you tried Animation Framework? - graphite
@graphite Actually, my project doesn't produce animation, it just do some processing of an image and then updates the image, so I think animation is not an appropriate option. Do you have any idea how to deal with problem by using QGraphicsItem? - JavaBeta
Do you give control to event loop while processing image? - graphite
@graphite Thanks for your reply! I found that repainting the viewport will do the job! So in the method, just call this->item->setPixmap( QPixmap::fromImage(*coloration->image) ); this->view->viewport()->repaint(); - JavaBeta
@JavaBeta thanks a lot spend so much time one that. And it was viewport. I think you should write this as a answer . And accept it yourself for readers. - Kadir Erdem Demir

2 Answers

0
votes

You must be blocking your event loop, or your implementation of the item is otherwise bad. I can't reproduce your issue.

0
votes

This worked for me: ui->graphicsView->viewport()->repaint();