如果你有一個簡單的委託來實現(和你在QML工作),你可以真的使用ListView
來完成工作。
這是一個獨立的佈局原型。通過Image
更改Rectangle
。當模型給出一個奇數或偶數時,您會發現顏色會有所不同。你可以用相同的方式改變Component
的加載方式,source
的Image
,無論你想象什麼。
import QtQuick 2.0
Rectangle {
width: 360
height: 200
ListView {
anchors.fill: parent
model: 3
delegate: Rectangle {
id: rect
width: parent.width
height: 60
property bool selected: false
color: selected ? "darkblue" : "transparent"
Rectangle {
id: bubbleIcon
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
width: 40
height: 40
color: "lightblue"
}
Text {
id: chatName
anchors.left: bubbleIcon.right
anchors.leftMargin: 10
height: parent.height
verticalAlignment: Text.AlignVCenter
text: "chat" + modelData
}
Rectangle {
id: notificationIcon
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
width: 40
height: 40
//just an dummy example to show how to change representation base
//expression binding
color: (modelData % 2 === 0) ? "lightGreen" : "red"
}
MouseArea {
anchors.fill: parent
onClicked: {
selected = ! selected;
}
}
}
}
}
來源
2013-12-12 10:15:54
jbh
任何想法,如果有一個例子在那裏我可以開始?真的覺得在這一點上輸了 – user3082584