Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Infinite scrolling of a qt listView in QML

Tags:

qt

qt5

qml

I have a listview object that reads data from a web api via a javascript function that appends the data to the listmodel. I've attached the listview and listmodel below.

I want to implement a type of infinite scroll when the user gets close or reaches the last element of the listview.

I can't figure out how to detect the scroll event and grab 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)
            }
        }
    }
like image 895
Smeegs Avatar asked Feb 26 '13 17:02

Smeegs


1 Answers

In QML every property has corresponding change signal. In your case you should listen atYEnd property of ListView:

ListView {
  id: messageList
  // Stuff
  onAtYEndChanged: {
    if (messageList.atYEnd) {
      // Loading tail messages...
    }
  }
}
like image 196
Pavel Osipov Avatar answered Nov 18 '22 02:11

Pavel Osipov