Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. AnimatedImage optimization?
QtWS25 Last Chance

AnimatedImage optimization?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 628 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Virgo
    wrote on last edited by
    #1

    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.
    Screenshot.png

    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

    1 Reply Last reply
    0
    • MarkkyboyM Offline
      MarkkyboyM Offline
      Markkyboy
      wrote on last edited by
      #2

      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.

      Don't just sit there standing around, pick up a shovel and sweep up!

      I live by the sea, not in it.

      V 1 Reply Last reply
      0
      • MarkkyboyM Markkyboy

        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.

        V Offline
        V Offline
        Virgo
        wrote on last edited by
        #3

        @Markkyboy

        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?

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved