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. Action shortcut missing in context menu
Forum Updated to NodeBB v4.3 + New Features

Action shortcut missing in context menu

Scheduled Pinned Locked Moved Solved General and Desktop
16 Posts 4 Posters 4.6k Views 2 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.
  • R Offline
    R Offline
    Rory_1
    wrote on last edited by
    #1

    My app uses the same menu structure for the main menu and the context menu for the central widget. The code looks like this:

    // main menu
    menuBar()->addAction(fileGroupAct);
    menuBar()->addAction(editGroupAct);
    menuBar()->addAction(goGroupAct);
    menuBar()->addAction(filterGroupAct);
    menuBar()->addAction(sortGroupAct);
    menuBar()->addAction(viewGroupAct);
    menuBar()->addAction(windowGroupAct);
    menuBar()->addAction(helpGroupAct);
    menuBar()->setVisible(true);
    
    // main context menu
    mainContextActions = new QList<QAction *>;
    mainContextActions->append(fileGroupAct);
    mainContextActions->append(editGroupAct);
    mainContextActions->append(goGroupAct);
    mainContextActions->append(filterGroupAct);
    mainContextActions->append(sortGroupAct);
    mainContextActions->append(viewGroupAct);
    mainContextActions->append(windowGroupAct);
    mainContextActions->append(helpGroupAct);
    
    // Central Widget mode context menu
    centralWidget->addActions(*mainContextActions);
    centralWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
    

    Main menu with shortcuts
    alt text

    Context menu without shortcuts
    alt text

    How do I get the context menu to show the action shortcuts?

    aha_1980A 1 Reply Last reply
    0
    • R Rory_1

      My app uses the same menu structure for the main menu and the context menu for the central widget. The code looks like this:

      // main menu
      menuBar()->addAction(fileGroupAct);
      menuBar()->addAction(editGroupAct);
      menuBar()->addAction(goGroupAct);
      menuBar()->addAction(filterGroupAct);
      menuBar()->addAction(sortGroupAct);
      menuBar()->addAction(viewGroupAct);
      menuBar()->addAction(windowGroupAct);
      menuBar()->addAction(helpGroupAct);
      menuBar()->setVisible(true);
      
      // main context menu
      mainContextActions = new QList<QAction *>;
      mainContextActions->append(fileGroupAct);
      mainContextActions->append(editGroupAct);
      mainContextActions->append(goGroupAct);
      mainContextActions->append(filterGroupAct);
      mainContextActions->append(sortGroupAct);
      mainContextActions->append(viewGroupAct);
      mainContextActions->append(windowGroupAct);
      mainContextActions->append(helpGroupAct);
      
      // Central Widget mode context menu
      centralWidget->addActions(*mainContextActions);
      centralWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
      

      Main menu with shortcuts
      alt text

      Context menu without shortcuts
      alt text

      How do I get the context menu to show the action shortcuts?

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by aha_1980
      #2

      Hi @Rory_1, welcome!

      Honestly, I'm not aware of an application showing shortcuts in a context menu. Most likely because of that, no such mechanism is implemented in Qt. But that is just guessing.

      Also, it looks like your context menu contains the same items as you main menu. But usually, a context menu contains context sensitive items, i.e. items that only apply at the position where the menu was opened.

      Qt has to stay free or it will die.

      R 1 Reply Last reply
      1
      • aha_1980A aha_1980

        Hi @Rory_1, welcome!

        Honestly, I'm not aware of an application showing shortcuts in a context menu. Most likely because of that, no such mechanism is implemented in Qt. But that is just guessing.

        Also, it looks like your context menu contains the same items as you main menu. But usually, a context menu contains context sensitive items, i.e. items that only apply at the position where the menu was opened.

        R Offline
        R Offline
        Rory_1
        wrote on last edited by
        #3

        @aha_1980 said in Action shortcut missing in context menu:

        Hi @Rory_1, welcome!

        Honestly, I'm not aware of an application showing shortcuts in a context menu. Most likely because of that, no such mechanism is implemented in Qt. But that is just guessing.

        This question shows it is possible: https://forum.qt.io/topic/82367/adding-more-actions-to-the-context-menu-of-a-spreadsheet-app

        Also, it looks like your context menu contains the same items as you main menu. But usually, a context menu contains context sensitive items, i.e. items that only apply at the position where the menu was opened.

        Understood. My app is designed to hide the main menu for a more compact form and for the menu to be accessible during slideshow mode, where only the image is visible.

        JonBJ 1 Reply Last reply
        0
        • R Rory_1

          @aha_1980 said in Action shortcut missing in context menu:

          Hi @Rory_1, welcome!

          Honestly, I'm not aware of an application showing shortcuts in a context menu. Most likely because of that, no such mechanism is implemented in Qt. But that is just guessing.

          This question shows it is possible: https://forum.qt.io/topic/82367/adding-more-actions-to-the-context-menu-of-a-spreadsheet-app

          Also, it looks like your context menu contains the same items as you main menu. But usually, a context menu contains context sensitive items, i.e. items that only apply at the position where the menu was opened.

          Understood. My app is designed to hide the main menu for a more compact form and for the menu to be accessible during slideshow mode, where only the image is visible.

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by
          #4

          @Rory_1 said in Action shortcut missing in context menu:

          This question shows it is possible: https://forum.qt.io/topic/82367/adding-more-actions-to-the-context-menu-of-a-spreadsheet-app

          Why don't you download its source and have a look at how it achieves it, then?

          R 1 Reply Last reply
          0
          • JonBJ JonB

            @Rory_1 said in Action shortcut missing in context menu:

            This question shows it is possible: https://forum.qt.io/topic/82367/adding-more-actions-to-the-context-menu-of-a-spreadsheet-app

            Why don't you download its source and have a look at how it achieves it, then?

            R Offline
            R Offline
            Rory_1
            wrote on last edited by
            #5

            @JonB said in Action shortcut missing in context menu:

            @Rory_1 said in Action shortcut missing in context menu:

            This question shows it is possible: https://forum.qt.io/topic/82367/adding-more-actions-to-the-context-menu-of-a-spreadsheet-app

            Why don't you download its source and have a look at how it achieves it, then?

            I did, but I don't see why it is working in that example based on looking at the code. I haven't been able to get the project to run yet to confirm it actually does what the image suggests though.

            JonBJ 1 Reply Last reply
            0
            • R Rory_1

              @JonB said in Action shortcut missing in context menu:

              @Rory_1 said in Action shortcut missing in context menu:

              This question shows it is possible: https://forum.qt.io/topic/82367/adding-more-actions-to-the-context-menu-of-a-spreadsheet-app

              Why don't you download its source and have a look at how it achieves it, then?

              I did, but I don't see why it is working in that example based on looking at the code. I haven't been able to get the project to run yet to confirm it actually does what the image suggests though.

              JonBJ Online
              JonBJ Online
              JonB
              wrote on last edited by JonB
              #6

              @Rory_1
              I don't know, but your screenshot looks different from that example. Is it possible that this uses a native OS/UI/desktop functionality to display the context menu, and that works for the icon on some other OS but not yours?

              R 2 Replies Last reply
              0
              • JonBJ JonB

                @Rory_1
                I don't know, but your screenshot looks different from that example. Is it possible that this uses a native OS/UI/desktop functionality to display the context menu, and that works for the icon on some other OS but not yours?

                R Offline
                R Offline
                Rory_1
                wrote on last edited by
                #7

                @JonB

                That's a good point. I'll fiddle around with my style sheet to see if it is the culprit.

                1 Reply Last reply
                0
                • JonBJ JonB

                  @Rory_1
                  I don't know, but your screenshot looks different from that example. Is it possible that this uses a native OS/UI/desktop functionality to display the context menu, and that works for the icon on some other OS but not yours?

                  R Offline
                  R Offline
                  Rory_1
                  wrote on last edited by
                  #8

                  @JonB
                  I tried without my style sheet and I still get the same thing so that does not appear to be the issue.

                  JonBJ 1 Reply Last reply
                  0
                  • R Rory_1

                    @JonB
                    I tried without my style sheet and I still get the same thing so that does not appear to be the issue.

                    JonBJ Online
                    JonBJ Online
                    JonB
                    wrote on last edited by
                    #9

                    @Rory_1
                    Are you Qt 5.10? Are you https://github.com/lxde/lxqt/issues/1426 ??

                    R 1 Reply Last reply
                    0
                    • JonBJ JonB

                      @Rory_1
                      Are you Qt 5.10? Are you https://github.com/lxde/lxqt/issues/1426 ??

                      R Offline
                      R Offline
                      Rory_1
                      wrote on last edited by
                      #10

                      @JonB said in Action shortcut missing in context menu:

                      @Rory_1
                      Are you Qt 5.10? Are you https://github.com/lxde/lxqt/issues/1426 ??

                      Yes, I am on 5.10 and that appears to be the issue - thanks for finding it!! Seems like an odd "improvement". I really appreciate the help.

                      BTW I did get the spreadsheet app to run and I did not see the shortcuts.

                      JonBJ 1 Reply Last reply
                      0
                      • R Rory_1

                        @JonB said in Action shortcut missing in context menu:

                        @Rory_1
                        Are you Qt 5.10? Are you https://github.com/lxde/lxqt/issues/1426 ??

                        Yes, I am on 5.10 and that appears to be the issue - thanks for finding it!! Seems like an odd "improvement". I really appreciate the help.

                        BTW I did get the spreadsheet app to run and I did not see the shortcuts.

                        JonBJ Online
                        JonBJ Online
                        JonB
                        wrote on last edited by
                        #11

                        @Rory_1
                        :)

                        BTW I did get the spreadsheet app to run and I did not see the shortcuts.

                        Probably also requires the fix for your 5.10.

                        R 1 Reply Last reply
                        0
                        • JonBJ JonB

                          @Rory_1
                          :)

                          BTW I did get the spreadsheet app to run and I did not see the shortcuts.

                          Probably also requires the fix for your 5.10.

                          R Offline
                          R Offline
                          Rory_1
                          wrote on last edited by
                          #12

                          @JonB

                          Right.

                          I hate to mark this issue as solved, but if that's the way Qt is going I guess I'll just have to live with it. I'll take a look at subclassing QStyleHints.

                          JonBJ 1 Reply Last reply
                          0
                          • R Rory_1

                            @JonB

                            Right.

                            I hate to mark this issue as solved, but if that's the way Qt is going I guess I'll just have to live with it. I'll take a look at subclassing QStyleHints.

                            JonBJ Online
                            JonBJ Online
                            JonB
                            wrote on last edited by
                            #13

                            @Rory_1
                            As per http://doc.qt.io/qt-5/qstylehints.html#showShortcutsInContextMenus-prop, this is a deliberately-introduced option now.

                            R 1 Reply Last reply
                            0
                            • JonBJ JonB

                              @Rory_1
                              As per http://doc.qt.io/qt-5/qstylehints.html#showShortcutsInContextMenus-prop, this is a deliberately-introduced option now.

                              R Offline
                              R Offline
                              Rory_1
                              wrote on last edited by
                              #14

                              @JonB

                              I understand - doesn't mean I have to agree with it. I've been thinking about how I would go about subclassing QStyleHints. I know how to subclass a widget that I can then use, but how do I subclass something I am not calling myself. Do I have to subclass QGuiApplication? Seems like that might be risky.

                              mrjjM 1 Reply Last reply
                              0
                              • R Rory_1

                                @JonB

                                I understand - doesn't mean I have to agree with it. I've been thinking about how I would go about subclassing QStyleHints. I know how to subclass a widget that I can then use, but how do I subclass something I am not calling myself. Do I have to subclass QGuiApplication? Seems like that might be risky.

                                mrjjM Offline
                                mrjjM Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on last edited by
                                #15

                                @Rory_1
                                Hi
                                Its being debated.
                                https://bugreports.qt.io/browse/QTBUG-61181?page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel&showAll=true
                                So there might come a Set method. Currently its read only :(

                                R 1 Reply Last reply
                                1
                                • mrjjM mrjj

                                  @Rory_1
                                  Hi
                                  Its being debated.
                                  https://bugreports.qt.io/browse/QTBUG-61181?page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel&showAll=true
                                  So there might come a Set method. Currently its read only :(

                                  R Offline
                                  R Offline
                                  Rory_1
                                  wrote on last edited by
                                  #16

                                  @mrjj
                                  Thanks for the info. Much appreciated.

                                  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