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. Refreshing remote Image source without flickering (resp. empty image during refresh)
Forum Updated to NodeBB v4.3 + New Features

Refreshing remote Image source without flickering (resp. empty image during refresh)

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 1.5k Views 1 Watching
  • 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.
  • D Offline
    D Offline
    DerMas
    wrote on last edited by
    #1

    I have a simple Image that uses a remote source (http://url.to/image.png). The problem is, if I change the image source to another url, the Image will be empty while it is fetching the image from the url (looks like a short flickering).
    How can I prevent the image from being empty while loading?

    Can I somehow force the Image to keep the old source while image.status equals to Component.loading?

    1 Reply Last reply
    2
    • D Offline
      D Offline
      DerMas
      wrote on last edited by
      #2

      My current way too complicated solution:

      @import QtQuick 2.2

      Rectangle {
      id: container
      property int imageVisible: 1
      property string initialSource
      property int fillmode

      color: "transparent"
      
      Image {
          id: image1
          anchors.fill: parent
          fillMode: fillmode
          clip: true
          visible: imageVisible === 1
          source: initialSource
      }
      
      Image {
          id: image2
          anchors.fill: parent
          fillMode: fillmode
          clip: true
          visible: imageVisible === 2
      }
      
      function setSource(source){
          var imageNew = imageVisible === 1 ? image2 : image1;
          var imageOld = imageVisible === 2 ? image2 : image1;
      
          imageNew.source = source;
      
          function finishImage(){
              if(imageNew.status === Component.Ready) {
                  imageNew.statusChanged.disconnect(finishImage);
                  imageVisible = imageVisible === 1 ? 2 : 1;
              }
          }
      
          if (imageNew.status === Component.Loading){
              imageNew.statusChanged.connect(finishImage);
          }
          else {
              finishImage();
          }
      }
      

      }

      @

      P 1 Reply Last reply
      2
      • D DerMas

        My current way too complicated solution:

        @import QtQuick 2.2

        Rectangle {
        id: container
        property int imageVisible: 1
        property string initialSource
        property int fillmode

        color: "transparent"
        
        Image {
            id: image1
            anchors.fill: parent
            fillMode: fillmode
            clip: true
            visible: imageVisible === 1
            source: initialSource
        }
        
        Image {
            id: image2
            anchors.fill: parent
            fillMode: fillmode
            clip: true
            visible: imageVisible === 2
        }
        
        function setSource(source){
            var imageNew = imageVisible === 1 ? image2 : image1;
            var imageOld = imageVisible === 2 ? image2 : image1;
        
            imageNew.source = source;
        
            function finishImage(){
                if(imageNew.status === Component.Ready) {
                    imageNew.statusChanged.disconnect(finishImage);
                    imageVisible = imageVisible === 1 ? 2 : 1;
                }
            }
        
            if (imageNew.status === Component.Loading){
                imageNew.statusChanged.connect(finishImage);
            }
            else {
                finishImage();
            }
        }
        

        }

        @

        P Offline
        P Offline
        pfjarschel
        wrote on last edited by
        #3

        @DerMas Did you ever find a better solution for this? I just implemented your idea and it works beautifully, but I was wondering if there was a simpler way...

        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