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. How get lower-case menu shortcut?
Forum Update on Monday, May 27th 2025

How get lower-case menu shortcut?

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 5 Posters 2.2k 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.
  • B Offline
    B Offline
    buckler
    wrote on last edited by
    #1

    Hello,
    I have been trying to get a lower-case menu shortcut key. I cannot see how to do it, it always comes out upper case. Here is my simple line of code:
    ToggleCoronalAction->setShortcut(Qt::Key_C|Qt::NoModifier);

    I just want a lower case c.

    kshegunovK K 2 Replies Last reply
    0
    • B buckler

      Hello,
      I have been trying to get a lower-case menu shortcut key. I cannot see how to do it, it always comes out upper case. Here is my simple line of code:
      ToggleCoronalAction->setShortcut(Qt::Key_C|Qt::NoModifier);

      I just want a lower case c.

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      @buckler
      I don't believe it's possible. What would be the difference between lowercase and uppercase letter anyway ...?

      Read and abide by the Qt Code of Conduct

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

        I think most people assume that when they press the key without a shift, it is the lower case, and to get the upper case, they would also press the shift. So part of it is trying to accord with user sense of what the key press is. But in addition to that, the purpose of the modifiers, not only shift but ctrl, alt, etc., is to expand the effective number of keys.

        This may allow re-formulation of my question. Is what I have coded correct, insofar as triggering on c without shift, but that the display reading as capital C doesn't reflect it correctly? in which case, then the question is how to get the shortcut to display correctly, i.e., to show 'c' instead of 'C' in this example?

        kshegunovK 1 Reply Last reply
        0
        • B buckler

          I think most people assume that when they press the key without a shift, it is the lower case, and to get the upper case, they would also press the shift. So part of it is trying to accord with user sense of what the key press is. But in addition to that, the purpose of the modifiers, not only shift but ctrl, alt, etc., is to expand the effective number of keys.

          This may allow re-formulation of my question. Is what I have coded correct, insofar as triggering on c without shift, but that the display reading as capital C doesn't reflect it correctly? in which case, then the question is how to get the shortcut to display correctly, i.e., to show 'c' instead of 'C' in this example?

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by kshegunov
          #4

          @buckler said:

          Is what I have coded correct, insofar as triggering on c without shift, but that the display reading as capital C doesn't reflect it correctly?

          I'd say yes. Still, having shortcuts bound to keys without modifiers is somewhat unusual.

          in which case, then the question is how to get the shortcut to display correctly, i.e., to show 'c' instead of 'C' in this example?

          As I said, I don't think it's possible through standard means (the only way I could fathom would be to have your own implementation of QMenu and QMenuBar). Maybe I'm wrong, and maybe someone will suggest something better , but don't hold your breath.

          EDIT:
          Well, now I look like an idiot. I completely forgot that there's implicit constructor for the key sequence that accepts QString. See the answers below.

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          0
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi
            While it will work to use "c" as shortcut for say an action in qtoolbar
            if you then place a textEdit on the form too, the shortcut will stop working
            if textedit has focus. At least my test did.

            Whereas if u use alt+c, it still works even if keyboard focus is on other widget.

            My guess is that using shortcut keys for toolbar or menu will have issues unless
            an modifier is used.

            1 Reply Last reply
            0
            • B buckler

              Hello,
              I have been trying to get a lower-case menu shortcut key. I cannot see how to do it, it always comes out upper case. Here is my simple line of code:
              ToggleCoronalAction->setShortcut(Qt::Key_C|Qt::NoModifier);

              I just want a lower case c.

              K Offline
              K Offline
              KeithS
              wrote on last edited by
              #6

              @buckler

              Am I missing something?

              setShortcut(tr("C")); // sets shortcut to lower case C
              setShortCut(tr("Shift+C")); // sets shortcut to uppercase C

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

                Hi,

                AFAIK, It's a bit simpler than that:

                setShortcut(tr("C")); // sets shortcut to key C
                setShortCut(tr("Shift+C")); // sets shortcut to key C with Shift modifier
                

                There's no notion of casing.

                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

                • Login

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