Reputation: 2621
I'm adding keyboard shortcuts to a QtQuick Controls2 application using Qt 5.8.0 and I would like to control a tab bar using QKeySequence like this:
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
}
}
This works for the NextChild sequence using Ctrl+Tab, however the PreviousChild sequence does not work. I checked the documentation and it claims in Windows the previousChild sequence is Ctrl+Shift+Tab, as I would have expected.
I added a console.log()
to check, whether the function gets called which it doesn't.
Since I am using identical code for both functions I can only assume the key sequence is wrong, or is there anything else I am missing?
Upvotes: 1
Views: 858
Reputation: 5336
This seems to be a Qt Bug https://bugreports.qt.io/browse/QTBUG-15746
Alternatively, you can define your previousChild shortcut as
Shortcut {
sequence: "Ctrl+Shift+Tab"
onActivated: {
tabBar.previousTab()
}
}
That is beside the point but there is a small index bug in your previousTab
implementation
function previousTab() {
console.log("previous tab")
if(currentIndex > 0) // Instead of (currentIndex - 1) > 0
currentIndex--
else
currentIndex = contentChildren.length-1
}
Upvotes: 1