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. Alt + Key, how to create QKeySequence?
Forum Update on Monday, May 27th 2025

Alt + Key, how to create QKeySequence?

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 2 Posters 580 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by
    #1

    So in a previous post I've got a hot key working with:

    int intHotKeyIdx(strText.indexOf(clsMainWnd::mscchHotKeyIndicator));
    if ( intHotKeyIdx >= 0 ) {
        const QString cstrHotKey(strText.mid(intHotKeyIdx + 1, 1));
        const QKeySequence cobjKeySeq(cstrHotKey);
        pobjAction->setShortcut(cobjKeySeq);
    }
    

    Where clsMainWnd::mscchHotKeyIndicator is set to &.

    This actually sets the hotkey to the letter only and doesn't require the Alt key to be depressed to action. I am now trying to fix this and failing:

    int intHotKeyIdx(strText.indexOf(clsMainWnd::mscchHotKeyIndicator));
    if ( intHotKeyIdx >= 0 ) {
        const QString cstrHotKey(strText.mid(intHotKeyIdx + 1, 1));
        QByteArray arybytHotKey(cstrHotKey.toAscii());
        const int cintHotKey(arybytHotKey[0]);
        const int cintAlt(Qt::ALT);
        pobjAction->setShortcut(cintAlt + cintHotKey);
    }
    

    Kind Regards,
    Sy

    1 Reply Last reply
    0
    • O Offline
      O Offline
      ollarch
      wrote on last edited by
      #8

      Could you try it with Ctrl instead of Alt? I think that Alt + 1..9 are used to switch between tabs.

      SPlattenS 1 Reply Last reply
      1
      • O Offline
        O Offline
        ollarch
        wrote on last edited by
        #2

        Can you try this?

        QString qShortcut = "Ctrl+";
        qShortcut.append(cstrHotKey);
        
        SPlattenS 1 Reply Last reply
        0
        • O ollarch

          Can you try this?

          QString qShortcut = "Ctrl+";
          qShortcut.append(cstrHotKey);
          
          SPlattenS Offline
          SPlattenS Offline
          SPlatten
          wrote on last edited by
          #3

          @ollarch , I just tried:

          setShortcut("Alt+1");
          

          It didn't work.

          Kind Regards,
          Sy

          1 Reply Last reply
          0
          • O Offline
            O Offline
            ollarch
            wrote on last edited by
            #4

            Where do you connect the QAction signal "triggered"?

            1 Reply Last reply
            0
            • SPlattenS Offline
              SPlattenS Offline
              SPlatten
              wrote on last edited by SPlatten
              #5

              @SPlatten said in Alt + Key, how to create QKeySequence?:

              It didn't work.

              QObject::connect(pobjAction, SIGNAL(triggered())
                                              ,pobjLambda, SLOT(lambdaSlot()));
              

              If I change the hot key to just '1' it works but I want the Alt+1 combo.

              Kind Regards,
              Sy

              1 Reply Last reply
              0
              • O Offline
                O Offline
                ollarch
                wrote on last edited by
                #6

                On wich OS? Maybe Alt+1 is OS reserved.

                1 Reply Last reply
                0
                • SPlattenS Offline
                  SPlattenS Offline
                  SPlatten
                  wrote on last edited by
                  #7

                  Its on Linux and Alt+1 is just an example, the hot keys could be any letter and Alt combo.

                  Kind Regards,
                  Sy

                  1 Reply Last reply
                  0
                  • O Offline
                    O Offline
                    ollarch
                    wrote on last edited by
                    #8

                    Could you try it with Ctrl instead of Alt? I think that Alt + 1..9 are used to switch between tabs.

                    SPlattenS 1 Reply Last reply
                    1
                    • O ollarch

                      Could you try it with Ctrl instead of Alt? I think that Alt + 1..9 are used to switch between tabs.

                      SPlattenS Offline
                      SPlattenS Offline
                      SPlatten
                      wrote on last edited by
                      #9

                      @ollarch , yes, that works, thank you.

                      Kind Regards,
                      Sy

                      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