page switch delay when loading images to Image source
-
Hi
I have pages organized with StackView, lets say second page has ListView with Image elements (usually 3 elements), when I switch from first page to second app freezes for about 300ms when ListView is loading pictures from disk. How to make ListView load its pictures after page is switched? I was experimenting with stackView onCurrentItemChanged but it looks like the currentItem is changed before it is really shown, I was adding some delays in PictureModel that provides file names for ListView but it does not work well.
Or maybe some other idea? Load pictures in C++ part maybe in separate thread and pass somehow content to QML ListView?
Parts of my code below://ListView from second page ListView { id: plantPicView snapMode: ListView.SnapOneItem highlightRangeMode: ListView.StrictlyEnforceRange orientation: Qt.Horizontal width:(PictureModel.rows ? parent.width : 0) height:(PictureModel.rows ? 3*width/4 : 0) anchors.horizontalCenter: parent.horizontalCenter clip: true z:10 model: PictureModel delegate: PictureDelegate { z:11 source: pic_name_role } spacing: 0 } //PictureDelegate.qml Rectangle { id: root width:plantPicView.width height:plantPicView.height color: "lightgray" property alias source: imageItem.source Image { id: imageItem anchors.fill: parent } } // part of PictureModel void PictureModel::setCatalogId(int catalog_id) { if(picMap.count()) { beginRemoveRows(QModelIndex(), 0, picMap.count()-1); QMapIterator<int,PictureModelDataStruct*> i(picMap); while(i.hasNext()) { i.next(); delete i.value(); } picMap.clear(); endRemoveRows(); } int row=0; QMap<int,PicDataStruct*> *pMap=catalogData->getPicMap(catalog_id); QMapIterator<int,PicDataStruct*> i(*pMap); while(i.hasNext()) { i.next(); PictureModelDataStruct *p=new PictureModelDataStruct; p->pic_id=i.value()->pic_id; p->row=row; p->fileName=QString("%1%2_%3.jpg").arg(Zm().imagesPath).arg(catalog_id).arg(p->pic_id); p->available=1 p->pic_desc=i.value()->pic_desc; picMap.insert(p->row,p); beginInsertRows(QModelIndex(), row, row); endInsertRows(); row++; } m_rows=picMap.count(); emit rowsChanged(); }
Best Regards
Marek -
Have you tried putting
asynchronous: true
in yourImage
instead ?