【发布时间】:2018-01-18 10:17:19
【问题描述】:
我正在使用 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() 来检查该函数是否被调用,而它没有。
由于我对这两个函数使用相同的代码,我只能假设键序列是错误的,或者还有什么我遗漏的吗?
【问题讨论】: