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. Problem with QAction's shortcut and QMenu
Qt 6.11 is out! See what's new in the release blog

Problem with QAction's shortcut and QMenu

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 9.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.
  • S Offline
    S Offline
    samkpo
    wrote on last edited by
    #1

    When i add an action to a QMenu, wich is added to QMenuBar() in QMainWindow, the QAction's shortcut works fine. But, when i do:
    @QMenuBar()->hide()@
    the shortcut doesn't answer anymore, any idea?

    1 Reply Last reply
    1
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      If you hide the menu, the action is also hidden if it is not used on any other object.
      Am I right, that it is not connected additionally to a toolbar?

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • S Offline
        S Offline
        samkpo
        wrote on last edited by
        #3

        You are right Gerolf, the actions added to the toolbar still answering to the shortcut. What do you suggest to fix that?

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #4

          If an action is completely hidden, it is disabled. If you need global shortcuts, event when the actions UI stuff is hidden, us "QShortcut":http://doc.qt.nokia.com/4.7/qshortcut.html

          @
          shortcut = new QShortcut(QKeySequence(tr("Ctrl+O", "File|Open")), this);
          shortcut->setContext(Qt::ApplicationShortcut);
          connect(shortcut, SIGNAL(activated ()), this, SLOT(fileOpen()));
          @

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • S Offline
            S Offline
            samkpo
            wrote on last edited by
            #5

            yeah, that works, and i've done something like that, but then if the menu is visible (hiding and showing is done by the user) i get to another problem:
            @QAction::eventFilter: Ambiguous shortcut overload: Ctrl+O@
            and the only thing comes to my mind is to implement something that manage the shortcuts according to the menu state, what's your opinion about that?

            1 Reply Last reply
            0
            • G Offline
              G Offline
              giesbert
              wrote on last edited by
              #6

              you could remove the shortcut from the action, as it is available by the shortcut instance :-)

              Nokia Certified Qt Specialist.
              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

              1 Reply Last reply
              0
              • S Offline
                S Offline
                samkpo
                wrote on last edited by
                #7

                yes, i can do that too, but it's going to be a pain in the a** since i need to consider wich action is in the toolbar (also configurable in the ui) :-P
                anyway, thanks you for answering so fast.

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  pbe
                  wrote on last edited by
                  #8

                  I found out that setting the height to 0 might do the job. The menu is gone, but the shortcuts are still working (tested under Qt 5.4.2).
                  ui->menuBar->setFixedHeight(0);

                  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