Can't set ListView.currentIndex
-
wrote on 27 Nov 2012, 19:52 last edited by
Hi
As the title says, I am not able to set currentIndex of the ListView...
I have the ListView defined in one file and the model and delegate in seperate files.
Everything seems to work fine except that I'm not able to set the currentIndex from the delegate.
It's not unlikely I'm doing something totally wrong...I'm still not super sharp in this.
Below is an example of what I'm trying to achieve...Thanks in advance.
Example:
myListView.qml
@ListView {
model: myModel
delegate: myDelegate {}
}
@myDelegate.qml
@Component {
// something
MouseArea {
onClicked {
ListView.currentIndex = index;
}
}
}@ -
wrote on 28 Nov 2012, 10:02 last edited by
First of all the problem is at the line:
@
ListView.currentIndex = index;
@You reference the property currentIndex through the type name of the component (ListView), not the id of the instance of the component as it should be.
You can either try to just write the following and see what happens:
@
currentIndex = index;
@Or in worst case scenario you can do something like the following:
myListView.qml
@
ListView {
model: myModel
delegate: myDelegate {
onClicked: currentIndex = index;
}
}
@myDelegate.qml
@
Component {
// something
signal clicked(int index)MouseArea { onClicked { parent.clicked(index) } } }
@
1/2