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

How to redraw certain area of window constantly when Main thread is busy.



  • Hi all,

    We’re developing a QWidget-base application on Linux.
    The window has certain area which need to be redrawn constantly, ideally 60fps.
    But it stops when the Main thread is busy, for example when app needs to redraw all areas following by certain event.

    Firstly we tried to use QtQuick, but the render thread is not completely independent from the Main thread.
    So the area still stopped when Main thread was busy.

    Secondly we’re trying the direct drawing using Wayland + EGL + OpenGL.
    We created an independent thread from Application and draw that area with Wayland + EGL + OpenGL.
    In this case, the area was drawn constantly even when the Main thread was busy.
    But it still has an issue that once the Main thread is activated by mouse click or touch, the area is hidden. We’ve not found a way to make the area always on top.

    If anyone know a solution, please let us know.
    We also welcome other ways to realize what we want.


  • Moderators

    @kosuke said in How to redraw certain area of window constantly when Main thread is busy.:

    But it stops when the Main thread is busy, for example when app needs to redraw all areas following by certain event

    it is the main thread, because drawing is happening there and only there.
    So there is no way around it, other to optimize your load on the main thread.


  • Banned

    This post is deleted!


  • @kosuke try to add a mutex lock in the paint event of that area. Only one thread is allowed to draw it.



  • @JoeCFD
    Are you suggesting that it is OK for different threads to do paint events provided they use a mutex?



  • @JonB It is multi-threading. The same area has to be painted one after another.



  • @JoeCFD
    Let me start by saying I have not done anything in this area, so your knowledge may be greater than mine.

    I understood that in Qt all UI operations must be performed in one UI thread, and no UI ops directly from other threads. I did not think this was just a mutex issue. And I kind of thought @raven-worx was implying the same. That's all I was thinking of.



  • This post is deleted!


  • Maybe simply override paintEvent(QPaintEvent event) of this area and call your draw function from paintEvent(QPaintEvent event) of this area. This draw func is called in your thread. Add mutex lock into it. Do not repaint the parent of this draw area. This means that this area is updated only from your func draw().


Log in to reply