Qt Quick:ObjectModel

一、描述


        对象模型ObjectModel用于在视图中显示可视项目,该类型可以将Qt Quick中的可视化项目作为数据项显示到视图上。
使用ObjectModel的视图不需要指定委托,ObjectModel已经包含了可视化的委托。
可使用model的附加属性index获取数据项的索引位置。

二、属性


count:int
index:int

三、函数


append(object item)
clear()
object get(int index)
insert(int index, object item)
move(int from, int to, int n)
remove(int index, int n)

四、代码示例

import QtQuick
import QtQuick.Controls

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")

    ObjectModel {
        id: iObjectModel
        Rectangle { width: 150; height: 50; color: "limegreen"; radius: 8 }
        Label { width: 150; height: 50; color: "limegreen"; text: "This is a Label"; font.pixelSize: 36 }
        Button { width: 150; height: 50; text: "This is a Button"; font.pixelSize: 16 }
        Row {
            spacing: 15
            Switch { text: checked ? "已打开" : "已关闭" }
            Switch { text: checked ? "已打开" : "已关闭" }
            Switch { text: checked ? "已打开" : "已关闭" }
        }
        ScrollView {
            width: 180
            Label { text: "This is a ScrollView!"; font.pixelSize: 48 }
        }
    }

    ListView {
        width: parent.width / 2
        height: parent.height
        anchors.horizontalCenter: parent.horizontalCenter
        spacing: 20

        model: iObjectModel
    }
}

五、运行结果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

喵呜角角

如果对你有所帮助,哪怕1毛钱~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值