属性
add : TransitionaddDisplaced : TransitioncacheBuffer : intcount : intcurrentIndex : intcurrentItem : ItemcurrentSection : stringdelegate : Componentdisplaced : TransitiondisplayMarginBeginning : intdisplayMarginEnd : inteffectiveLayoutDirection : enumerationfooter : ComponentfooterItem : ItemfooterPositioning : enumerationheader : ComponentheaderItem : ItemheaderPositioning : enumerationhighlight : ComponenthighlightFollowsCurrentItem : boolhighlightItem : ItemhighlightMoveDuration : inthighlightMoveVelocity : realhighlightRangeMode : enumerationhighlightResizeDuration : inthighlightResizeVelocity : realkeyNavigationEnabled : boolkeyNavigationWraps : boollayoutDirection : enumerationmodel : modelmove : TransitionmoveDisplaced : Transitionorientation : enumerationpopulate : TransitionpreferredHighlightBegin : realpreferredHighlightEnd : realremove : TransitionremoveDisplaced : TransitionreuseItems : boolsectionsection.criteria : enumerationsection.delegate : Componentsection.labelPositioning : enumerationsection.property : stringsnapMode : enumerationspacing : realverticalLayoutDirection : enumeration
模型model
view所管理的所有的数据都存放在该模型中,以供代理进行显示操作
代理delegate
代理决定如何操作模型中存放的数据
ListView {id: listwidth: 180; height: 200model: ListModel {ListElement {name: "Bill Smith"number: "555 3264"}ListElement {name: "John Brown"number: "555 8426"}ListElement {name: "Sam Wise"number: "555 0473"}}spacing: 20//当前项高亮highlight: Rectangle {color: "lightsteelblue";}delegate: Rectangle {color: "transparent"width: list.widthheight: 20Text{id: txttext: name + ": " + number}MouseArea{anchors.fill: parentonClicked: {//修改当前项currentIndex = indexconsole.log(index)}}}}
拖拽回弹效果
Flickable
interactive : bool 拉动回弹属性
flickableDirection: Flickable.HorizontalFlick //设置回弹方向与使能delegate: Row {Text { text: '<b>Name:</b> ' + name; width: 160 }Text { text: '<b>Number:</b> ' + number; width: 160 }}
页眉header\页脚footer
Rectangle{id: rectborder.width: 2border.color: "red"width: 400height: 200anchors.centerIn: parentListView {id: listanchors.fill: rect// width: 180// height: 200header: Rectangle{width: list.widthheight: 20color:"blue"}footer:Rectangle{width: list.widthheight: 20color: "#22222211"}footerPositioning:ListView.OverlayFooter //页脚位置设置model: ListModel {ListElement {name: "Bill Smith"number: "555 3264"}ListElement {name: "John Brown"number: "555 8426"}ListElement {name: "Sam Wise"number: "555 0473"}}spacing: 20//当前项高亮highlight: Rectangle {color: "lightsteelblue";}delegate: Rectangle {color: "transparent" //每项元素的底色width: list.widthheight: 20Text{id: txttext: name + ": " + number}MouseArea{anchors.fill: parentonClicked: {//修改当前项currentIndex = indexconsole.log(index)}}}//滑动回弹效果flickableDirection: Flickable.HorizontalFlick// delegate: Row {// Text { text: '<b>Name:</b> ' + name; width: 160 }// Text { text: '<b>Number:</b> ' + number; width: 160 }// }}}
section分组显示
Rectangle{id: rectborder.width: 2border.color: "red"width: 400height: 200anchors.centerIn: parentListView {id: listanchors.fill: rectmodel: ListModel {ListElement {name: "Bill Smith"number: "555 3264"size: "small"}ListElement {name: "John Brown"number: "555 8426"size: "medium"}ListElement {name: "Sam Wise"number: "555 0473"size: "big"}}spacing: 20//当前项高亮highlight: Rectangle {color: "lightsteelblue";}//滑动回弹效果flickableDirection: Flickable.HorizontalFlickdelegate: Row {Text { text: '<b>Name:</b> ' + name; width: 160 }Text { text: '<b>Number:</b> ' + number; width: 160 }}Component {id: sectionHeadingRectangle {width: rect.widthheight: 20color: "lightsteelblue"required property string sectionText {text: parent.sectionfont.bold: truefont.pixelSize: 20}}}section.property: "size" //分组排列依据section.criteria: ViewSection.FullString //控制property对应的size显示方式 是全字符 还是首字符section.delegate: sectionHeading //控制section的每一个property如何绘制}}

