这里用到了ListView.isCurrentItem判断是否是当前项目
import QtQuick 2.0
Item {
id: root
width: 1920
height: 1080
ListView {
width: 600
height: 800
anchors.centerIn: parent
model: 5
delegate:
Rectangle {
id: delegateItem
width: 100
height: 50
color: ListView.isCurrentItem? "pink":"lightblue"
Text {
anchors.centerIn: parent
text: index
font.pixelSize: 30
}
border.color: "black"
MouseArea {
anchors.fill: parent
onClicked: delegateItem.ListView.view.currentIndex = index
}
}
}
}