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 Updated to NodeBB v4.3 + New Features

How get lower-case menu shortcut?

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 5 Posters 2.2k Views 4 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
    buckler
    wrote on 15 Apr 2016, 13:48 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.

    K K 2 Replies Last reply 15 Apr 2016, 15:11
    0
    • B buckler
      15 Apr 2016, 13:48

      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
      kshegunov
      Moderators
      wrote on 15 Apr 2016, 15:11 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 15 Apr 2016, 16:13 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?

        K 1 Reply Last reply 15 Apr 2016, 16:25
        0
        • B buckler
          15 Apr 2016, 16:13

          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?

          K Offline
          K Offline
          kshegunov
          Moderators
          wrote on 15 Apr 2016, 16:25 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
          • M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 15 Apr 2016, 16:37 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
              15 Apr 2016, 13:48

              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 15 Apr 2016, 18:56 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
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 15 Apr 2016, 21:17 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

                3/7

                15 Apr 2016, 16:13

                • Login

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