Qml上拉下拉刷新

作者: zhengtianzuo | 来源:发表于2018-11-29 20:38 被阅读0次

当ListView拉动到一定位置的时候 就需要出现Loading
然后加载数据进行刷新

所以我们通过states来进行拉动位置的判断

    ListView {
        id: listView
        width: parent.width
        height: parent.height
        model: listModel
        delegate: Rectangle{
            height: 24
            width: parent.width
            border.color: "#AAAAAA"
            border.width: 1
            Text {
                font.family: "microsoft yahei"
                font.pixelSize: 15
                anchors.centerIn: parent
                text: name + ": " + number
            }
        }
        states: [
            State {
                id: downRefresh
                name: "downRefresh"; when: (listView.contentHeight > 0) && (listView.contentY > (listView.contentHeight - root.height + nPullHeight))
                StateChangeScript {
                    name: "funDownRefresh"
                    script: funDownRefresh()
                }
            },
            State {
                id: upRefresh
                name: "upRefresh"; when: (listView.contentY < -nPullHeight)
                StateChangeScript {
                    name: "funUpRefresh"
                    script: funUpRefresh()
                }
            }
        ]
    }
show.gif

需要完整代码请访问QtQuickExamples

相关文章

网友评论

    本文标题:Qml上拉下拉刷新

    本文链接:https://www.haomeiwen.com/subject/lelqcqtx.html