High CPU usage on QWidget's update()

  • Hi, I'm trying to find out the source of a high CPU usage. I have already tried to comment out all code in the paintEvent() but it didn't helped. However the CPU usage dropped rapidly when I stopped calling the update() function.

    Some facts about the device/app

    • The app uses QWS
    • it is a full screen app

    Any idea how to optimize the code? What to check?

  • Lifetime Qt Champion


    How are you calling update and why ?

  • In our code we call update(QRect) multiple times to update each visualisation object.
    How does exactly work the update(QRect) in respect to paintEvent()? In our code we call update(QRect) multiple times. Will the paintEvent be called also multiple times or only once with the overall region including all rectangles?

  • Lifetime Qt Champion

    Calls to update should schedule a paint event to happen so it should not trigger an immediate repaint. However I don't know how it can optimize this if you call update repeatedly with rectangles of different sizes.

  • Qt Champions 2017

    @Radim, @SGaist
    Paint events are (ordinarily) compressed (as with keyboard events), so multiple calls to update generate a single paint event, provided the pending one was not consumed. Depending on the rect/region passed, the engine marks the first ancestral native widget's area as dirty and schedules a paint event. Ultimately, the dirty regions are united (geometrically) and a paint event is delivered when appropriate.

    If you're painting your widget with opaque colors and respect the QRegion instance passed along with the paint event, you could most probably safely set either the Qt::WA_NoSystemBackground attribute, or depending on the case even the Qt::WA_OpaquePaintEvent attribute. This'd skip the background erasing done by Qt and you should be able to squeeze a bit more out of the widget.

  • After some testing it seems the bottle neck is the video memory throughput.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.