[Solved] Select an item in an interactive ListView
-
Is it possible to select an item with a mouse click in an interactive ListView?
As soon as I set interactive: true, I cannot select any elements in the ListView. Do I have to set another property?
-
setting interactive true enables to interact with the flickable area of the listview. Can you be more clear on what you mean by selecting an item? If you just need to highlight a selected item use highlight property.
-
Sorry that my question was not that precise.
I have set the highlight and I can also see it.
When I press the keyboard up / down arrows, the highlight moves from one item to the other.
But when I click on an item, the highlight is not moved to the clicked item.E.g. if I've got that list, the one with the --- is the highlighted one.
Item1
---Item2---
Item3
Item4I press down:
Item1
Item2
---Item3---
Item4Now I press up:
Item1
---Item2---
Item3
Item4Now I click on Item4:
Item1
---Item2---
Item3
Item4The highlight still stays on Item2, even though I want Item4 to be highlighted, and I don't know why.
-
Try using "highlightfollowscurrentitem":http://doc.qt.nokia.com/4.7-snapshot/qml-listview.html#highlightFollowsCurrentItem-prop property of ListView.
-
I have tried that, but it still does not work.
This is what my ListView looks like:
@
ListView {
id: listView
focus: true
width: 400; height: 250
anchors.bottomMargin: 50
anchors.fill: parent
currentIndex: 1
highlight: highlight
model: myModel
delegate: MultiDelegate {}
boundsBehavior: Flickable.StopAtBounds
clip: true
highlightFollowsCurrentItem: true
onCurrentIndexChanged: console.log("current index changed")
onCurrentItemChanged: console.log("current item changed")
ScrollBar
{
flickable: listView
vertical: true
}
}
@when I click on an item, there is no output "current index changed" or "current item changed"
-
I found the solution to the problem.
In my delegate, I have added a MouseArea.
in the onClicked of this MouseArea I've added:
@
onClicked: listView.currentIndex = index
@
Now the ListView is doing everything I want. It is flickable, you can can go up and down with the keyboard and you can click an item with the mouse to highlight it.