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 bind Ctrl C to delete Key

How to bind Ctrl C to delete Key

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 1.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.
  • Q Offline
    Q Offline
    Qt Enthusiast
    wrote on last edited by
    #1

    Hi
    I have a QTableWidget and I have to bind Ctrl + key and Delete to TQableWIdget

    on Ctrl +C - I should be able to clear the contents of selected row

    on Delete key I should be able to delete the selected row

    Can someone help me in writing a prototype code for the same

    1 Reply Last reply
    0
    • Maaz MominM Offline
      Maaz MominM Offline
      Maaz Momin
      wrote on last edited by
      #2

      If that widget is MainWindow, you can create QShortcut http://doc.qt.io/qt-5/qshortcut.html

      If you want only for that widget override your keyPressEvent to check for Ctrl+C.
      https://forum.qt.io/topic/20982/solved-how-to-handle-all-the-keys-in-key-press-release-event/2

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

        Hi,

        On a side note, it's not a good idea to use CTRL+C to clear something. People are used to use that shortcut to copy something. While you are free to use whatever combo you want, you are likely going to take your users by surprise as your application would behave counter intuitively.

        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
        4
        • Q Offline
          Q Offline
          Qt Enthusiast
          wrote on last edited by
          #4

          yeah I think I mean CTrl + X

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

            Other nitpick: CTRL+X is for cut. Therefore it should remove stuff but users also expect to be able to past what they have cut somewhere else.

            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
            • M Offline
              M Offline
              mpergand
              wrote on last edited by mpergand
              #6

              Agree with @SGaist

              Why not CTRL+del or CTRL+backspace
              This is what I'm using:

              // CTRL+BS
              #ifdef Q_OS_MAC
                   shortcut= new QShortcut(QKeySequence(Qt::META+Qt::Key_Backspace),this);
              #else
                   shortcut= new QShortcut(QKeySequence(Qt::CTRL+Qt::Key_Backspace),this);
              #endif
                connect(shortcut,SIGNAL(activated()),this,SLOT(applicationShortcut()));
              
              1 Reply Last reply
              1
              • Q Offline
                Q Offline
                Qt Enthusiast
                wrote on last edited by Qt Enthusiast
                #7

                @mpergand said in How to bind Ctrl C to delete Key:

                 shortcut= new QShortcut(QKeySequence(Qt::META+Qt::Key_Backspace),this);
                

                what is key good for good for deleting the row of QtableWidget

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

                  Could be shift or ctrl + delete or even all three to ensure people don't do that by accident. The combination @mpergand suggested with backspace is not a bad idea either.

                  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