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. page switch delay when loading images to Image source
Forum Updated to NodeBB v4.3 + New Features

page switch delay when loading images to Image source

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 882 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.
  • M Offline
    M Offline
    Marek
    wrote on last edited by Marek
    #1

    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

    1 Reply Last reply
    0
    • GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #2

      Have you tried putting asynchronous: true in your Image instead ?

      M 2 Replies Last reply
      1
      • GrecKoG GrecKo

        Have you tried putting asynchronous: true in your Image instead ?

        M Offline
        M Offline
        Marek
        wrote on last edited by
        #3

        @GrecKo would that be so simple? ;) I will check and let you know.
        Thanks
        Marek

        1 Reply Last reply
        0
        • GrecKoG GrecKo

          Have you tried putting asynchronous: true in your Image instead ?

          M Offline
          M Offline
          Marek
          wrote on last edited by
          #4

          @GrecKo thanks, obviously it works :)

          Marek

          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