一個鏈表模型(ListModel)是由許多個鏈表元素(ListElement)組成。
import QtQuick 2.0 Column{ spacing: 2 Repeater{ model:ListModel{ ListElement{name:"單機"; surfaceColor:"gray"} ListElement{name:"聯機"; surfaceColor:"yellow"} } Rectangle{ width: 100 height: 20 radius: 3 color: "lightBlue" Text { anchors.centerIn: parent text: name } Rectangle{ anchors.left: parent.left anchors.verticalCenter: parent.verticalCenter anchors.leftMargin: 2 width: 16 height: 16 radius: 8 border.color: "black" border.width: 1 color: surfaceColor } } } }
結果:
Column { spacing: 2 Repeater { model: 10 delegate: Rectangle { width: 100 height: 20 radius: 3 color: "lightBlue" Text { anchors.centerIn: parent text: index } } } }