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

qkeyevent ctrl+c

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 2 Posters 4.2k Views 1 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.
  • S Offline
    S Offline
    s002wjh
    wrote on last edited by s002wjh
    #1

    how to catch ctrl+c/or other keys event press or release for qkeyevent or other method?

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

      Hi
      In a widget or Application wide ?
      You can use
      http://doc.qt.io/qt-5/qshortcut.html#details
      For app global "hotkeys"

      S 1 Reply Last reply
      0
      • mrjjM mrjj

        Hi
        In a widget or Application wide ?
        You can use
        http://doc.qt.io/qt-5/qshortcut.html#details
        For app global "hotkeys"

        S Offline
        S Offline
        s002wjh
        wrote on last edited by
        #3

        @mrjj
        in widget mode

        mrjjM 1 Reply Last reply
        0
        • S s002wjh

          @mrjj
          in widget mode

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

          @s002wjh
          You mean inside a widget when it has keyboard focus ?
          You can always make a custom widget and override
          keyPress.

          Can you explain the use case ?
          Its a bit vague what you are trying to do and there are multiple ways with keys depending
          on what you need it for.

          S 1 Reply Last reply
          0
          • mrjjM mrjj

            @s002wjh
            You mean inside a widget when it has keyboard focus ?
            You can always make a custom widget and override
            keyPress.

            Can you explain the use case ?
            Its a bit vague what you are trying to do and there are multiple ways with keys depending
            on what you need it for.

            S Offline
            S Offline
            s002wjh
            wrote on last edited by
            #5

            @mrjj

            yes in my widget, i have zoom in function for my graph. I would like use ctrl+key to reset the display, so its max zoom out.

            as i understand this require something like this

            if(keyEvent->key() == Qt::Key_C && keyEvent->modifiers().testFlag(Qt::ControlModifier)){
            ...
            }

            mrjjM 1 Reply Last reply
            0
            • S s002wjh

              @mrjj

              yes in my widget, i have zoom in function for my graph. I would like use ctrl+key to reset the display, so its max zoom out.

              as i understand this require something like this

              if(keyEvent->key() == Qt::Key_C && keyEvent->modifiers().testFlag(Qt::ControlModifier)){
              ...
              }

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

              @s002wjh
              Hi
              You can use the shortcut for fast way or simply override the
              mousePress virtual function and check there for your custom widget.
              You might need to set Focus Policy for it to accept keys.

              S 1 Reply Last reply
              0
              • mrjjM mrjj

                @s002wjh
                Hi
                You can use the shortcut for fast way or simply override the
                mousePress virtual function and check there for your custom widget.
                You might need to set Focus Policy for it to accept keys.

                S Offline
                S Offline
                s002wjh
                wrote on last edited by
                #7

                @mrjj

                i like to know if this syntax is correct, hard to find the example.

                if(keyEvent->key() == Qt::Key_C && keyEvent->modifiers()==Qt::ControlModifier){
                ...
                }

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

                  Hi
                  Yes it works :)
                  alt text

                  
                  class MainWindow : public QMainWindow {
                    Q_OBJECT
                  .....
                   protected:
                    virtual void keyPressEvent(QKeyEvent* keyEvent) override {
                      if(keyEvent->key() == Qt::Key_C && keyEvent->modifiers() == Qt::ControlModifier) {
                        qDebug() << "CTRL +c";
                      }
                    }
                  
                  S 1 Reply Last reply
                  0
                  • mrjjM mrjj

                    Hi
                    Yes it works :)
                    alt text

                    
                    class MainWindow : public QMainWindow {
                      Q_OBJECT
                    .....
                     protected:
                      virtual void keyPressEvent(QKeyEvent* keyEvent) override {
                        if(keyEvent->key() == Qt::Key_C && keyEvent->modifiers() == Qt::ControlModifier) {
                          qDebug() << "CTRL +c";
                        }
                      }
                    
                    S Offline
                    S Offline
                    s002wjh
                    wrote on last edited by
                    #9

                    @mrjj
                    hmm i guess i must done something wrong. i gotta double check my code.

                    mrjjM 1 Reply Last reply
                    0
                    • S s002wjh

                      @mrjj
                      hmm i guess i must done something wrong. i gotta double check my code.

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

                      @s002wjh
                      Hi
                      Make sure to use the override directive so it warns you if
                      its not really overriding anything.

                      do you have compiler error or in what way dont work ?
                      Did you do this in a custom widget ?
                      You might need to allow focus then. Default its off.
                      alt text
                      Try set to Click focus. then click on your widget and press ctrl+c

                      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