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 to get 'Shift+1' string sequence from 'Shift+!' QKeyEvent?

How to get 'Shift+1' string sequence from 'Shift+!' QKeyEvent?

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 3.9k 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
    bodzio131
    wrote on 5 Apr 2013, 15:22 last edited by
    #1

    Hi,

    When I press 'Shift+1' then from QKeyEvent I get key '!' + Qt::ShiftModifier.
    How can I get original 'Shift+1' key sequence string here?
    Or from different side: how to create valid QShortcut from 'Shift+!' string sequence which will handle 'Shift+1' key press?

    I tried to create QKeySequence and use toString() method, but I got 'Shift+!' instead of 'Shift+1'.

    Best regards,
    Bogdan

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 5 Apr 2013, 21:00 last edited by
      #2

      Hi,

      IIRC, you can't shift plus a letter/number will give you the upper cased letter, the character over the number etc... To have a ‘Shift+!’ shortcut you would need a sequence like shift, shift, ! which is not possible

      Have a look at the "QKeySequence":http://qt-project.org/doc/qt-4.8/qkeysequence.html#keyboard-layout-issues layout issues doc

      Hope it helps

      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
        bodzio131
        wrote on 6 Apr 2013, 13:58 last edited by
        #3

        Well, I don't want to have 'Shift+!' shortcut. However, I want to create 'shortcut editor' inside my app. Imagine that user wants to set 'Shift+1' shortcut, so he presses 'Shift+1' and then I need to a) show 'Shift+1' in my app (but I get 'Shift+!'), and b) create valid shortcut using string sequence ('Shift+1' shortcut of course).
        I found one solution, but it's ugly: first I create QShortcut for every problematic shortcut sequence, and then I use them instead of QKeyEvent. But this way I cannot be sure that I handle every weird key sequence :(

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 6 Apr 2013, 21:16 last edited by
          #4

          Add to that that other countries have other keyboard layouts and that would be event more complicated ;)

          Have a look at QtCreator's shortcut editor for inspiration. With my keyboard Shift+1 = + (not Shift +, just +)

          If you don't want to end in world of pain, follow the standard: shortcuts are being made with CTRL, META, ALT with SHIFT used in conjunction with one or more of the first three keys.

          Hope it will ease your work

          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
            bodzio131
            wrote on 6 Apr 2013, 22:44 last edited by
            #5

            First of all thank you for your time and clues.

            I need to clarify that by Shift+1 I meant 'press Shift along with 1', not 'press Shift along with + and with 1'. Sorry for misguiding you.

            Unfortunately CTRL, META, ALT with SHIFT seem not to be valid solution too. Try 'CTRL SHIFT 1' in QtCreator, you will get unusable shortcut 'CTRL SHIFT !' :(

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 7 Apr 2013, 19:56 last edited by
              #6

              You're welcome !

              I understood you right and that was exactly my point: there are some combinations that are simply invalid or not feasible and these can change between keyboard layouts (trust me, there are many different).

              Don't try to trick the system to make them work, you would end up having to maintain a very complex beast. Also think of the consequences of having a shortcut of shift+1 while editing a text ?

              Hope it helps

              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
                bodzio131
                wrote on 7 Apr 2013, 21:59 last edited by
                #7

                You're right about editing text and Shift+1, there is clear conflict. So from the other side: do you see any possibility to recognize/block such shortcuts? I wouldn't like to give possibility to define something which cannot be used. Any ideas?

                1 Reply Last reply
                0

                1/7

                5 Apr 2013, 15:22

                • Login

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