[英]Infinite scrolling of a qt listView in QML
I have a listview object that reads data from a web api via a javascript function that appends the data to the listmodel. 我有一个listview对象,它通过一个javascript函数从web api读取数据,该函数将数据附加到listmodel。 I've attached the listview and listmodel below.
我已经在下面附上了listview和listmodel。
I want to implement a type of infinite scroll when the user gets close or reaches the last element of the listview. 我想在用户靠近或到达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)
}
}
}
In QML every property has corresponding change signal. 在QML中,每个属性都有相应的变化信号。 In your case you should listen atYEnd property of ListView:
在你的情况下你应该听ListView的YEnd属性:
ListView {
id: messageList
// Stuff
onAtYEndChanged: {
if (messageList.atYEnd) {
// Loading tail messages...
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.