[Solved] Showing "loading" animation while updating the QGraphicsScene (thread problem)
I'm using Qt 4.8.
I have a big QGraphicsScene to update (it takes 3 secs to append the new QGraphicsObjects).
I would like to show the user that the update is in progress.
In particular I thought about showing a loading wheel on screen and than remove it when the update ends.
The problem here is that I should make the wheel visible and then not visible in the
same thread of the scene update. This because:
It is not allowed to edit graphic properties outside the gui thread.
I cannot move the computation in a "worker thread" since it involves graphics.
This results in the wheel not showing at all, since when the view is updated the wheel
has been already set visible and then not visible again:
/... big computation involving graphics .../
/... here GUI is updated, thus the wheel doesn't show up.../
Is there anything I can do?
One option is to call "qApp->processEvents":http://qt-project.org/doc/qt-4.8/qcoreapplication.html#processEvents at regular intervals (e.g. inside a loop) during your "big computation" phase.
See "this article":http://www.informit.com/articles/article.aspx?p=1405544&seqNum=3 also.
Thanks for the tips, it works and the article is very interesting.