找回密码
 立即注册
收起左侧

QML 中如何更新Model的数据

0
回复
7094
查看
[复制链接]
累计签到:1 天
连续签到:1 天
来源: 2021-3-1 13:01:27 显示全部楼层 |阅读模式
1Qter豆

我写了一个小程序,实现页面循环的滑动:

PetsModel.qml文件:

import QtQuick 2.0
ListModel {


    ListElement {
        name: "Polly"
        type: "Parrot"
        age: 12
        size: "Small"
    }
    ListElement {
        name: "Penny"
        type: "Turtle"
        age: 4
        size: "Small"
    }
}



HightRange.qml文件:

import QtQuick 2.0


Rectangle {
    id: root
    property int current: 0
    property bool increasing: true
    property int count: 0


    PathView {
        id: view
        anchors.fill: parent
        snapMode: PathView.SnapOneItem
        highlightRangeMode: PathView.StrictlyEnforceRange
        currentIndex: -1
        model: PetsModel {id: aModel}


        delegate: petDelegate
        path: Path {


            startX: -view.width / 2 // let the first item in left
            startY: view.height / 2 // item's vertical center is the same as line's
            PathLine {
                relativeX: view.width * view.model.count // all items in lines
                relativeY: 0
            }
        }


    }


    Component {
        id: petDelegate
        Item {
            width: 480
            height: 800


            Rectangle{
                anchors.fill: parent
                Text {
                    id: first
                    width: parent.width
                    height: parent.height / 3
                    anchors.top:parent.top
                    text: name
                }
                Text {
                    id: second
                    anchors.top:first.bottom
                    width: parent.width
                    height: parent.height / 3
                    text: type
                }
                Text {
                    id: third
                    anchors.top:second.bottom
                    width: parent.width
                    height: parent.height / 3
                    text: age
                }
            }


            MouseArea {
                anchors.fill: parent
                onClicked: root.current = index
            }
        }
    }
}



main.qml文件:

import QtQuick 2.9
import QtQuick.Window 2.2


Window {
    visible: true
    width: 480
    height: 800
    title: qsTr("Hello World")
    HightRange {
        anchors.fill:parent
    }
}

这样出来的界面上显示的信息是固定的,无法改变,我想实现界面上的信息定时改变该怎么做?例如在不滑动界面的情况下每秒age加一


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

公告
可以关注我们的微信公众号yafeilinux_friends获取最新动态,或者加入QQ会员群进行交流:190741849、186601429(已满) 我知道了