import QtQuick.Window 2.2
import QtQuick.Controls 2.2
Window {
visible: true
title: qsTr("Hello World")
ListView{
id:listView
anchors.fill: parent
model: 10
snapMode: ListView.SnapOneItem
orientation:ListView.Horizontal
delegate: Rectangle{
width: listView.width
height: listView.height
color: index%2 ? "red":"yellow"
Label{
anchors.centerIn: parent
font.pointSize: 100
text: index
}
}
}
}
snapMode: ListView.SnapOneItem // 将切换模式设置为单张切换;
orientation:ListView.Horizontal //将列表改成水平浏览模式。
highlightRangeMode: ListView.StrictlyEnforceRange //切换 item 的时候将 currentIndex 也跟随着变化
boundsBehavior:Flickable.StopAtBounds //禁止列表首尾滑动
maximumFlickVelocity:7000 //设置滑动的最大速度
listView设置headerItem:
header: Rectangle{
width: listView.width
height: 70
color: "green"
Label{
anchors.centerIn: parent
text: "this is header"
}
}
原文链接:(5条消息) QML ListView几个常用且非常重要的属性_luoyayun361的博客-CSDN博客