Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Qt 带键导航的QML ListView_Qt_Qml_Qqmlcomponent - Fatal编程技术网

Qt 带键导航的QML ListView

Qt 带键导航的QML ListView,qt,qml,qqmlcomponent,Qt,Qml,Qqmlcomponent,QML-我有一个列表视图,它由触摸、按键导航或侧面向上/向下导航按钮控制。ListView用于程序的不同部分,并且列表中的项目数始终不同。当使用键导航(keyPressLeft)从侧面导航转到ListView时,我想将焦点设置到ListView当前页面的中间。我们现在使用的代码适用于每页有5个项目的列表,但它需要更加动态。下面是我们现在使用的代码: Keys.onLeftPressed: { var first = menu.indexAt(0, menu.conten

QML-我有一个列表视图,它由触摸、按键导航或侧面向上/向下导航按钮控制。ListView用于程序的不同部分,并且列表中的项目数始终不同。当使用键导航(keyPressLeft)从侧面导航转到ListView时,我想将焦点设置到ListView当前页面的中间。我们现在使用的代码适用于每页有5个项目的列表,但它需要更加动态。下面是我们现在使用的代码:

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()     
}