AnimatedImage optimization?
-
Hi folks,
I have code like this
import QtQml 2.15 import QtQuick 2.15 import QtQuick.Window 2.15 import QtQuick.Controls 2.15 import QtQuick.Layouts 1.15 Window { width: 640 height: 480 visible: true title: qsTr("Hello World") ScrollView { anchors.fill: parent id: view objectName: "view" Column { width: parent.width Repeater { model: 100 Button { AnimatedImage { anchors.fill: parent id: image cache: true source: "file:/home/virgo/Pictures/Rotating_earth_(large).gif" onPlayingChanged: if (!playing) playing = true } implicitWidth: parent.width implicitHeight: width * image.sourceSize.height / image.sourceSize.width } } } contentWidth: availableWidth clip: true } }
and this is the gif i used (its simple and small)
and the thing is, if i have the AnimatedImages' cache set to true, its gonna eat up gigabytes of my RAM; but if i set them to false then its gonna be lagging crazy.
here's the screenshot i took when running the above code.
first line is when cache set to false, the other is when cache set to true.
is there any way i can make them only play when its absolutely necessary (e.g. when on or just partially on screen)?
or is there a better solution?thanks in advance
-
Your code is somewhat confusing. Why 100 buttons?, and where are the buttons when the image is running?, what do the buttons do?,
By reducing the number of buttons to one, the animation is smoother, also I placed the gif into the project's folder rather than calling it from elsewhere on my hdd.
With 100 buttons, the image freezes for a moment, like there is a struggle to load each button which loads the animated image each time, no wonder you are seeing high ram usage.
-
You are right that makes no sense to use Buttons here, i just wanted a "container widget with mouse events" and Button was the first one came into my mind, so...
actually i tried using just Items as containers and the results were pretty much the same thing. (the screenshot of the gnome system monitor was taken after the program started for a while, i had to make sure all the AnimatedImages are loaded)And yes in practice we dont put 100 same AnimatedImages in one view, we'll have different gifs... imagine a gallery app or something.
the program is just for test purpose, it doesnt matter if it populate same AnimatedImage items. in fact if it cannot handle same gif well, hows it gonna handle different gifs?