QML 怎么在gridview中用Index定位? 怎么在代理中设置背景?

import QtQuick 1.0

Item {
id: me
width: 100
height: 300

GridView {
id: grid
anchors.fill: parent

model: 60
cellHeight: 20
cellWidth: 20

property int colcount: Math.floor(width / cellWidth)

delegate: Rectangle {
width: grid.cellWidth
height: grid.cellHeight
color: {
var rowIndex = Math.floor(index / grid.colcount);
switch (rowIndex % 3) {
case 0:
return "yellow";
case 1:
return "blue";
case 2:
return "grey";
}
}

Text {
anchors.centerIn: parent
font.pixelSize: 15
text: index
}
}
}
}

posted on 2012-03-26 13:47  盐味  阅读(1268)  评论(0编辑  收藏  举报