Fixing bug with shortcuts no longer working when using MixedMenu.

This commit is contained in:
Ad5001 2021-07-22 22:44:14 +02:00
parent 092a101d2d
commit f2de022f2a
Signed by: Ad5001
GPG key ID: EF45F9C6AFE20160
3 changed files with 38 additions and 0 deletions

View file

@ -62,6 +62,14 @@ Item {
onToggled: root.toggled()
}
Component.onCompleted: {
// Forwarding to MenuBar. Little hack to make Action shortcuts work properly, because otherwise, they would not trigger
if(shortcut != 0) {
console.log("Adding shortcut for", text, "with shortcut", shortcut)
parent.parent.addShortcut(shortcut, root.triggered)
}
}
/*!
\qmlmethod void Action::toggle()
Toggles the \c checked state to its opposite state.
@ -70,4 +78,10 @@ Item {
root.trueItem.toggle()
}
/*!
\qmlmethod void Action::addShortcut(keysequence sequence, var trigger)
*/
function addShortcut(sequence, trigger) {
}
}

View file

@ -192,4 +192,13 @@ Item {
controlsMenu.popup()
}
}
/*!
\qmlmethod void Menu::addShortcut(keysequence sequence, var trigger)
Forwarding to MenuBar. Little hack to make Action shortcuts work properly, because otherwise, they would not trigger
\sa MenuBar::addShortcut
*/
function addShortcut(sequence, trigger) {
parent.parent.addShortcut(sequence, trigger)
}
}

View file

@ -82,4 +82,19 @@ Item {
function clear(){
root.trueItem.clear()
}
/*!
\qmlmethod void MenuBar::addShortcut(keysequence sequence, var trigger)
Little hack to make Action shortcuts work properly.
*/
function addShortcut(sequence, trigger) {
var newShortcut = Qt.createQmlObject(`
import QtQuick 2.12;
Shortcut {
context: Qt.ApplicationShortcut
}`, root, "shortcut" + sequence);
newShortcut.sequence = sequence
newShortcut.activated.connect(trigger)
console.log("Added shortcut " + sequence)
}
}