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继承而来的,