【发布时间】:2017-12-16 22:23:01
【问题描述】:
我想知道为什么这不起作用?
ListView {
id: root
property var selection: QtObject {}
...
delegate: MyView {
focused: ListView.isCurrentItem
selected: root.selection[index] === true
Rectangle {
id: selectionOverlay
anchors.fill: parent
color: "red"
opacity: 0.3
visible: selected
}
}
Keys.onPressed: if (event.key === Qt.Key_Space) {
if(!root.selection[root.currentIndex])
root.selection[root.currentIndex] = true;
else
root.selection[root.currentIndex] = false;
}
}
也就是说,委托不会对选择对象中的更改做出反应。只有在重新创建索引的委托时才能看到选择(例如,当滚动足够远并向后滚动时)。
将root.selection[index] 更改为ListView.view.selection[index] 也无济于事。
我需要在 ListView 级别进行选择以管理多选内容。 一直在敲我的头。
谢谢!
【问题讨论】: