[Solved] Select an item in an interactive ListView
-
wrote on 9 Jan 2012, 13:06 last edited by
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?
-
wrote on 10 Jan 2012, 12:34 last edited by
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.
-
wrote on 10 Jan 2012, 13:05 last edited by
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.
-
wrote on 10 Jan 2012, 13:33 last edited by
Try using "highlightfollowscurrentitem":http://doc.qt.nokia.com/4.7-snapshot/qml-listview.html#highlightFollowsCurrentItem-prop property of ListView.
-
wrote on 10 Jan 2012, 13:37 last edited by
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"
-
wrote on 10 Jan 2012, 14:50 last edited by
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.
3/6