Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[Solved] Showing "loading" animation while updating the QGraphicsScene (thread problem)



  • Hi all,

    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:

    @
    showWheel();
    /... big computation involving graphics .../
    hideWheel();
    /... here GUI is updated, thus the wheel doesn't show up.../
    @

    Is there anything I can do?

    Thanks



  • 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.


Log in to reply