Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Actions for MenuItem in multiple files?

Actions for MenuItem in multiple files?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 415 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    FSXAC
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    1

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved