Important: Please read the Qt Code of Conduct -

Creating QImage from a QML component?

  • I'm wondering if it's possible to convert QML components to a QImage type, or something similar.

    To be exact, I'm thinking about a Rectangle and a ProgressBar, since they are visual components, in theory it should be possible to convert them to something like a QImage?

    What I'm trying to do is using libopenshot, burn one of the components on to the video as an overlay, but for that I need them in a format it can recognize, and a QImage seems closes to it.

    My idea is to create a subclass of each component and draw it to the user in QML, while having the object reference so it can be added to the video. But I'm not sure of how to make it work.

    Would a QPainter be able to do the trick, or a QQuickPaintedItem? Handing the object (QGraphicsItem?) to it and draw/"convert" it?

    Since I never done something of that sort, I'm a bit stuck at what are the possible options for the solution.

    Any help is highly appreciated.

  • Moderators

    You can use Item's grabToImage method.

  • Thank you, I think this will do just perfect!

Log in to reply