Important: Please read the Qt Code of Conduct -

Modify the qsvg plugin to support animation with AnimatedImage - Possible?

  • In a Qt Quick Controls 2 project, I need to draw several animated SVG. As the AnimatedImage doesn't support the SVG animation, I could find a solution to achieve that by creating my own c++ component and by using a timer to refresh the animation every x time. For that reason I know that my animated SVG are supported correctly by the QtSvg renderer.

    However I want a solution supported natively by the AnimatedImage qt quick control. Actually I'm able to compile and modify the code of the native QtSvg module, as well as its qsvg plugin, which is the bridge between the QtSvg module and the QImageIOHandler interface, used by the AnimatedImage to draw the content.

    But even if I add the necessary code in the plugin to support the animation (Animation property support, functions related to the animation, ...), the AnimatedImage component continue to draw a static SVG.

    I dug a lot in the plugin's caller source code, and I deduced some conclusions:

    • The plugin caller cache the frames in several QPixmap, and read the animation loop only once (then the cache is replayed)
    • The read() function is called several times in the plugin if, an only if, the source image file is divided in frames, like it's the case e.g in GIF images, or in cursor (.cur) files, so a frame is read and cached, then the file cursor is moved to the next frame, and the next frame is read and cached, and so on
    • For that reason the way the SVG images are animated may be incompatible with the Qt animated image engine, because the whole SVG data are read only once, which notifies the engine that the image contains only one frame, instead of considering that the frame count should be determined by the duration and the FPS

    For that reason I have the following questions:

    • Are my above conclusions correct? If not, how is working the AnimatedImage and the Qt image plugins under the hood?
    • Is there a way to create a Qt image plugin which supports the animated SVG images? If yes, how can I do that?
    • I could not find a good, well explained document about how to create animated image plugin, can someone advise me one?
    • Why Qt didn't plan to support animated SVG natively, and is there anything planned in the future to fix a such situation?

    NOTE I know that I may use the QtWebEngine to support animated SVGs, but it's not an option for me, because:

    1. QtWebEngine adds ~300Mo to my application. As its current size is ~10Mo, a such increase isn't relevant to just show several animated images.
    2. QtWebEngine brings several side effects in my case, which have no response, like e.g:

    So please don't propose a such alternative as a solution.