QImage and QPixmap in a Qt Quick item

For reasons I don’t know, apparantly a Qt Quick Item that can show a QImage or a QPixmap is kind of missing. The current Image QML item only works with data that can be represented by a URL.

So I wrote one that kind of works. Comments most welcome.

It is found on git.kde.org: http://quickgit.kde.org/?p=scratch/sune/imageitem.git

Oh, and the KDE End of Year fundraiser is still running. https://www.kde.org/fundraisers/yearend2014/. Go support it if you haven’t already.

7 comments on “QImage and QPixmap in a Qt Quick item
    • Sune Vuorela says:

      Oh. I wasn’t even aware that I was reinventing a sharable wheel. I asked around if such a thing existed, and no one knew. But apparantly I didn’t look enough and asked the right people.

      Anyways. It was also a interesting learning experience.

  1. Kevin Krammer says:

    Granted not as straight forward, but I think one can use QImage or QPixmap with the Image element through a QQuickImageProvider

    • Sune Vuorela says:

      Kevin: How do you pass the QImage/QPixmap into the QQuickImageProvider ? I tried it, but only base64 encoded data in QString was the way that looked possible

  2. TheBootroo says:

    What about using the standard Image { }, but with a C++ method that converts QImage/QPixmap into an URI :


    It just works !

    • Sune Vuorela says:

      But then I would need to encode it to png format and then have the QML engine decode it again. Isn’t that a bit .. double?

  3. Simon says:

    One advantage of the URL approach over setting plain images is that with URLs you can support high-dpi setups with automatic loading of @2x, etc. images.