[英]highlight QML ListView Item on mouse click
我注意到列表視圖將自動/默認突出顯示第一項我如何禁用它並僅突出顯示我在鼠標單擊時選擇的項目?
Component {
id: highlight
Rectangle {
width: 180; height: 40
color: "lightsteelblue"; radius: 5
y: list.currentItem.y
Behavior on y {
SpringAnimation {
spring: 3
damping: 0.2
}
}
}
}
ListView {
id: list
width: 180; height: 200
model: ContactModel {}
delegate: Text {
text: name
MouseArea{
anchors.fill: parent
onClicked: {
list.currentIndex = index
}
}
}
highlight: highlight
highlightFollowsCurrentItem: false
focus: true
}
我已經完成了鼠標部分,但我堅持在項目附加時禁用突出顯示。
默認情況下, currentIndex
設置為0
,這就是為什么第一個項目總是開始突出顯示的原因。 您可以通過簡單地將currentIndex
初始化為 -1 來關閉它。
ListView {
currentIndex: -1
...
}
好的,經過幾個小時的搜索,我使用了onCountChanged
信號來指示添加到列表中的項目,然后 rest 將ListView
currentIndex
設置為-1
,所以代碼將是這樣的
onCountChanged: {
list.currentIndex = -1
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.