QML- I have a ListView that is controlled by either touch, key navigation, or by side up/down navigation buttons. The ListView is used in different parts of the program and always has a different number of items in the list. I want to set the focus to the middle of the current page of the ListView when the key navigation (keyPressLeft) is used to go from the side navigation to the ListView. The code that we are using right now works for a list that has 5 items per page, but it needs to be more dynamic. Here is the code we are using now:
Keys.onLeftPressed: {
var first = menu.indexAt(0, menu.contentY+5)
var mid
if (first == menu.count-1) {
mid = first
} else if (first ==menu.count-2) {
mid = first+1
} else {
mid = first+2
}
menu.currentIndex= mid //menu.indexAt(0, menu.contentY+5) + 2
keyPressLeft.currentItem.forceActiveFocus()
}