Qt listView infinite scroll in QML

I have a listview object that reads data from a web api through a javascript function that adds data to a listmodel. Below is a listview of listview and listmodel.

I want to implement an infinite scroll type when the user approaches or reaches the last element of the list.

I cannot figure out how to determine the scroll event and get the relative scroll position.

Thanks for any help.

ListModel {

        id: subModel
        function getSub(idx){
            return (idx >=0 && idx < count) ? get(idx).display_name: "";
        }
    }

ListView {
        clip: true
        width: parent.width
        height: parent.height - searchButton.height
        model: subModel         
        on
        delegate: ListingDelegate{
                text: title;
                subText: subTitle;
                icon: Qt.resolvedUrl(thumbnail)
                __iconWidth: units.gu(5)
                __iconHeight: units.gu(5)
            }
        }
    }
+5
source share
1 answer

In QML, each property has a corresponding change signal. In your case, you should listen to the atYEnd ListView property:

ListView {
  id: messageList
  // Stuff
  onAtYEndChanged: {
    if (messageList.atYEnd) {
      // Loading tail messages...
    }
  }
}
+6
source

All Articles