QML Animated Image collapses when scrolling away from it, and reappear when reaching it
-
Hi @vudangkhoa2906 you are loading the .gif image to the source from Online or you have the local copy of it ?
I did write a test sample code where the .gif was loaded properly in the View.
I have the .gif file in the Qt Resource file.Below is the output:
-
you can try to activating
https://doc.qt.io/qt-5/qml-qtquick-listview.html#delayRemove-attached-propIt might help. But you should show your qml code.
-
hi @Pradeep-P-N in my app, I load the gifs from online source (giphy)
for more information, it's a mobile app. I will check if the same problem happens with desktop app -
hi @J.Hilk
thank you for your suggestion. I will try it.
Here is the code of the delegate item:delegate: Column{
id:delegateMessage
width: parent.width
opacity: 1
scale: 1Rectangle{ height: gifMessageAnimatedImage.implicitHeight + 20 width: 200 x:10 radius: 6 AnimatedImage { id: gifMessageAnimatedImage x:10 y:10 width: 200 source: gifUrl onStatusChanged: { console.log("DEBUG_onStatusChanged:", status) } } }
}
-
@vudangkhoa2906
The problem is most likely that your source is a internet link.The not displayed views get destroyed and recreated later on and each time they have to download the gif, before its displayed.
I would suggest, on completion of your QML file, download the gifs to
QStandardPaths::TempLocation
and use that now local file for your delegate. -
@J.Hilk
you're right. I just tried replacing the gifUrl with a local url and they don't collapse.
Could you please explain your solution clearer? Like how do I download those files? And with each item in the model, how could it know which is the right gif from those downloaded to pass to the delegate ? And when I move to another page, could I remove those files downloaded previously? -
Hi @vudangkhoa2906
Can you please tell why are you using the online URL ?
Is there any major reason or purpose for Online resource and why cant you download them and use the local copy in the code ?Just have a look in to the The Qt Resource System
-
hi @Pradeep-P-N
it's a chatting app. the server only store the url of the images. when a user get the url of the gif, they should load the gif from online source. I don't think it would be a good idea to store gifs locally. -
Hi @vudangkhoa2906
Could you please try the same using Repeater QML Type instead of ListView. -
hi @Pradeep-P-N
I'll try as you suggested. However, I would still prefer ListView, since it support more functionalities that Repeater does.
And I also found a work-around with my problem. I add a placeholder ( a loading activity indicator) and set its visibility to true if the AnimatedImage is loading. That way the whole view does not get collapsed every time the image unload