在下面的代码中,如果委托项是矩形,则突出显示甚至不起作用 虽然Rectangle继承了Item,这是一个bug,还是我错过了什么。
ListView {
width: 200
height: 500
focus: true
highlight: Component {
Rectangle {
width: 200
height: 20
color: "red"
}
}
model: ListModel {ListElement {name: "dummy 1"} ListElement {name: "dummy 2"}}
delegate: Item { // If Item is replaced with Rectangle highlight does not work even though Rectangle inherits Item
width: 200
height: 20
Text {
text: name
}
}
}
答案 0 :(得分:2)
您必须将委托矩形的颜色设置为透明。默认情况下,矩形的颜色为白色,而项目是透明的。
ListView {
width: 200
height: 500
focus: true
highlight: Component {
Rectangle {
width: 200
height: 20
color: "red"
}
}
model: ListModel {ListElement {name: "dummy 1"} ListElement {name: "dummy 2"}}
delegate: Rectangle {
width: 200
height: 20
color: "transparent"
Text {
text: name
}
}
}