PDA

View Full Version : Get the first element of a ListView



nick85
2nd September 2013, 09:04
Hi all,

I'm quite newbie with QML.
I'm managing the focus changing (by tab/back-tab) on all my application.
I was able to manage it for all my items except for the ListView.

When tab is hit, in my listView I want to do something like:

[...]
var firstElement = getFirstElement();
firstElement.forceActiveFocus();
[...]

I don't want to use currentIndex if possible because I'm trying to use common APIs for all components. I want a way to get the element.

In my code the problem is the function called "getFirstElement".
I've tried to get the element by

listView.children[0].children[0]
but don't works because "listView.children[0].children" is not aligned to the model. I've read that ListView loads the internal element dynamically.. therefore the index 0 is not the first element but only the first visible list element.

I also tried to store the listView children when component is loaded but the problem is that in that moment are loaded only visible list elements.

In other words what I need would be: how can I get a complete list of all the elements of the ListView?
is there a way to get it?

thank you

bounce
2nd September 2013, 13:38
isn't what you want to do ?

http://qt-project.org/doc/qt-5.0/qtquick/qml-qtquick2-listview.html#positionViewAtBeginning-method

nick85
2nd September 2013, 13:47
No.. or I don't think so..

I need the deletege component.. or better i need the list of all delegate component sorted as the model to do something like this (in my library that manage focus):


sortedChildren[0].forceActiveFocus();

or


sortedChildren[n].forceActiveFocus();


edit:
I've tried with:

Component.onCompleted:
{
positionViewAtEnd()
}

something is changed but the order of the children is still wrong compared to the model