Qml 的Image對應的source不變,但是圖片內容改變卻不會刷新的解決方案


問題描述和解決方案:

 

 onCutImage: {
            if(isAdded){
                currentModel.insert(currentModel.count, {"imageURL":String(cutImagePrefix + url), "notifyVisible":true})
            }
            else{
                currentModel.set(imgIndex, {"imageURL": "", "notifyVisible":true})//1.先把路徑置空
                currentModel.set(imgIndex, {"imageURL":String(cutImagePrefix + url), "notifyVisible":true})//2.然后再設置成應該的路徑
} picEdit.close() }
 Image{
        id:imgItem
        cache:false//3.把Image的cache屬性設置為false
        asynchronous:true
        source: ""
        sourceSize.width: 30/ratio
        sourceSize.height:30/ratio
        smooth: true
    }

1.因為新版本的Qt的圖片緩存機制,導致相同路徑的圖片只會加載一次。所以要cache = false

2.因為model.set的object是一樣的,可能沒有觸發model數據的刷新,所以要先set(index, {"imageURL" :""})

兩個地方修改之后完美解決~


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM