【发布时间】:2015-04-19 04:53:30
【问题描述】:
import QtQuick 2.0
import Qt.labs.folderlistmodel 2.0
Item
{
Component {
id: highlight
Rectangle {
id: rooot
width: 180; height: 20
color: ListView.isCurrentItem ? "black" : "red"; radius: 5
y: list.currentItem.y
Behavior on y {
SpringAnimation {
spring: 3
damping: 0.2
}
}
}
}
ListView {
id: list
width: 480; height: 400
model: folderModel
delegate: Text { id: h; text: fileName }
highlight: highlight
highlightFollowsCurrentItem: false
focus: true
}
FolderListModel
{
id: folderModel
folder: "/home/anisha/"
nameFilters: ["*"]
}
}
这仅在我使用键盘时有效。如何让它在鼠标点击时工作?
【问题讨论】:
-
您需要在您的委托中插入
MouseArea并提供下一个代码:MouseArea { anchors.fill: parent; onClicked: list.currentIndex = index } -
@troyane 谢谢,我在发布这个问题后发现。
-
最好以相反的顺序进行:)