QtQuick2快捷方式未触发
我正在使用Qt5.8.0将键盘快捷键添加到QtQuick Controls2应用程序中,并希望使用QKeySequence控制选项卡栏,如下所示:QtQuick2快捷方式未触发,qt,qml,qt5,qtquick2,Qt,Qml,Qt5,Qtquick2,我正在使用Qt5.8.0将键盘快捷键添加到QtQuick Controls2应用程序中,并希望使用QKeySequence控制选项卡栏,如下所示: ApplicationWindow { ... Shortcut { sequence: StandardKey.NextChild onActivated: tabBar.nextTab() } Shortcut { sequence: StandardKey.PreviousChild
ApplicationWindow {
...
Shortcut {
sequence: StandardKey.NextChild
onActivated: tabBar.nextTab()
}
Shortcut {
sequence: StandardKey.PreviousChild
onActivated: tabBar.previousTab()
}
}
TabBar {
id: tabBar
...
function nextTab() {
console.log("next tab")
if((currentIndex + 1) < contentChildren.length)
currentIndex += 1
else
currentIndex = 0
}
function previousTab() {
console.log("previous tab")
if((currentIndex - 1) > 0)
currentIndex -= 1
else
currentIndex = contentChildren.length - 1
}
}
ApplicationWindow{
...
捷径{
序列:StandardKey.NextChild
onActivated:tabBar.nextTab()
}
捷径{
序列:StandardKey.PreviousChild
onActivated:tabBar.previousTab()
}
}
塔巴{
id:tabBar
...
函数nextTab(){
console.log(“下一个选项卡”)
if((currentIndex+1)0)
当前索引-=1
其他的
currentIndex=contentChildren.length-1
}
}
这适用于使用Ctrl+Tab的下一个子序列,但是上一个子序列不起作用。我检查了,它在Windows中声明前面的子序列是Ctrl+Shift+Tab,正如我所预料的那样
我添加了一个console.log()
来检查函数是否被调用。
由于我对这两个函数使用相同的代码,我只能假设键序列是错误的,或者我还缺少什么?这似乎是一个Qt错误
或者,您可以将上一个子快捷方式定义为
Shortcut {
sequence: "Ctrl+Shift+Tab"
onActivated: {
tabBar.previousTab()
}
}
这与问题无关,但在previousTab
实现中存在一个小的索引错误
function previousTab() {
console.log("previous tab")
if(currentIndex > 0) // Instead of (currentIndex - 1) > 0
currentIndex--
else
currentIndex = contentChildren.length-1
}