我正在使用Qt 5.8.0向QtQuick Controls2应用程序添加键盘快捷键,并希望使用QKeySequence控制选项卡栏,如下所示:
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
}
}这适用于使用Ctrl+Tab的NextChild序列,但是PreviousChild序列不起作用。我检查了documentation,它在Windows中声称previousChild序列是Ctrl+Shift+Tab,正如我所预期的那样。
我添加了一个console.log()来检查函数是否被调用了,因为我对两个函数使用了相同的代码,所以我只能假设按键顺序是错误的,或者我还遗漏了什么?
发布于 2018-01-18 22:39:58
这似乎是一个Qt错误https://bugreports.qt.io/browse/QTBUG-15746
或者,您可以将previousChild快捷方式定义为
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
}https://stackoverflow.com/questions/48318842
复制相似问题