Important: Please read the Qt Code of Conduct -

Drawing directly manipulated bitmaps fast

  • Hi,

    Usual topic, although I didn't find suitable answer yet.
    Please don't route me to OpenGL as I would like to draw transparent Qt widgets into the scene and AFAIK Qt's OpenGL view is not part of Qt's graphics context.
    I'd use OpenGL as render to texture, than I'd want to draw that texture into Qt context, fast.

    I have tried this sample code. For 640x640 resolution on 20FPS, it eats up 20% CPU on a fast notebook, with Linux and Cinnamon Desktop.

    Is there any more efficient solution?

  • Moderators

    hi @Andy32 ,

    from the sample code you gave. The most cpu intensive operation would probably be the construction of a new QImage, each cycle.


    Keep a QImage in memory and modify pixel that changed (QImage::setPixel)
    However set pixel is pretty slow as well, the docu suggest scanLine() or bits() to edit pixels directly, should be a lot faster.

    And if thats not enough, you could potentially split the Pixel manipulation in sectors and use different Threads for each sector.

  • Thanks for the tip for QImage.bits(). I have tried it out. I do minimal update on bits() in every cycle. It works. The CPU usage is still around 20%. But not the Qt process eats up the CPU rather the cinnamon process. Maybe this efficiency issue is related to Cinnamon's compositor and cannot be improved from Qt side.

Log in to reply