Actions for MenuItem in multiple files?
Unsolved
QML and Qt Quick
-
Hi,
I am trying to make a context menu and a menu-bar menu (they are in different files) to "share" the same action.
So I tried putting Action in a Singleton (in a separate
.qml
). It looks like this:// MenuActions.qml pragma Singleton Item { Action { id: action1 text: qsTr("Action 1") shortcut: "Ctrl+A" onTriggerd: console.log("action 1 triggered") } function action1() { return action1 } }
And my
.qml
files that contains the menu-bar or the context menu has this such that both invokes the same Action's:Menu { title: qsTr("Title Name") MenuItem { action: MenuActions.action1() } // ... }
For the most part, this works. However, the keyboard shortcut no longer works. (Pressing
Ctrl+A
- which is assigned in the property of Action in the singleton file - won't trigger the action).Is there a better way to implement something like this? Are there any work-around?
Thanks so much in advance.
Cheers.