QML -- > ListView(列表视图)

1、对于用户,ListView是一个滚动区域,支持惯性滚动。(代理项delegates)

import QtQuick 2.0

Rectangle{
    width: 80
    height: 300
    color: "white"

    ListView{
        anchors.fill: parent
        anchors.margins: 20

        clip:true

        model:100

        delegate: numberDelegate
        spacing: 5
    }
    Component{
        id:numberDelegate
        Rectangle{
            width: 40
            height: 40
            color: "lightGreen"

            Text{
                anchors.centerIn: parent

                font.pixelSize: 10
                text:index
            }
        }
    }
}

Component只能包含一个顶层Item,而且在这个Item之外不能定义任何数据,除了id。 在顶层Item之内,则可以包含更多的子元素来协同工作,最终形成一个具有特定功能的组件。

Component通常用来给一个View提供图形化组件,比如ListVIew::delegate属性就需要一个Component来指定如何显示列表的每一个项,又比如ButtonStyle::background属性也需要一个Component来指定如何绘制Button的背景。  

  Component不是Item的派生类,而是从QQmlComponent继承而来的,

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值