Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Shortcut for QAction without QMenuBar

Shortcut for QAction without QMenuBar

Scheduled Pinned Locked Moved General and Desktop
12 Posts 3 Posters 3.1k Views 1 Watching
  • 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.
  • B Offline
    B Offline
    butterface
    wrote on last edited by
    #1

    Isn't it possible to define a shortcut for a QAction which is part of a QMenu but not added to a QMenuBar. I tried to set the context to ApplicationShortcut but the action seems not to get triggered.

    Thanks!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What is the shortcut ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • B Offline
        B Offline
        butterface
        wrote on last edited by
        #3

        I the case I tested it was Ctrl + H

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Can you show the code where you setup your action ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • B Offline
            B Offline
            butterface
            wrote on last edited by
            #5

            @
            m_ActionHistory = new QAction(tr("History"), this);
            m_ActionHistory->setStatusTip(tr("History"));
            m_ActionHistory->setShortcut(Qt::CTRL + Qt::Key_H);
            m_ActionHistory->setShortcutContext(Qt::ApplicationShortcut);
            connect(m_ActionHistory, SIGNAL(triggered()), this, SIGNAL(OnHistory()));
            @

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              I meant the complete setup, with this there's no information about whether you do it in a QWidget, I a custom QMenu etc.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • B Offline
                B Offline
                butterface
                wrote on last edited by
                #7

                The action is added to a QMenu with parent this (where this is among others a QWidget). This QMenu normally is shown on right click (customContextMenuRequested) and the click on the menu entry triggers the slot. The menu is created once and not deleted until the end of life of the QWidget.

                Any further information needed?

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  thebeast44
                  wrote on last edited by
                  #8

                  it sounds like you're creating the action inside the customContextMenu setup. that way, I think the shortcut is only valid while the context menu is active. try creating the action outside of the context menu setup

                  1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    butterface
                    wrote on last edited by
                    #9

                    No, the menu and the action is created during the initialization. All of them i. e. the QMenu and the QAction are class members. In the slot which is called from the customContextMenuRequested only the QMenu::exec is called anymore.

                    1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      thebeast44
                      wrote on last edited by
                      #10

                      Ok, I haven't actually tried giving QAction a shorcut key sequence so I can't really help you with that. How about this?

                      @
                      QShortcut * shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_M), this);
                      connect(shortcut, SIGNAL(activated()), this, SLOT(showMinimized()));
                      @
                      I use this kind of shortcut directly connected to the class.

                      1 Reply Last reply
                      0
                      • B Offline
                        B Offline
                        butterface
                        wrote on last edited by
                        #11

                        The problem is that I don't want to have a bunch of shortcut objects around as I think that QAction should actually handle this. Also another connect is needed then.

                        1 Reply Last reply
                        0
                        • B Offline
                          B Offline
                          butterface
                          wrote on last edited by
                          #12

                          And the second problem is, that the menu entry of course does not show the shortcut. Is that somehow possible to achieve?

                          1 Reply Last reply
                          0

                          • Login

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