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. Shortcut QLineEdit
QtWS25 Last Chance

Shortcut QLineEdit

Scheduled Pinned Locked Moved General and Desktop
7 Posts 5 Posters 5.0k 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.
  • M Offline
    M Offline
    maxvanceffer
    wrote on last edited by
    #1

    I need created shortcut grabber, such as used in Qt Creator keyboard mapping. Can any body tell, if something already exist in free use. Or point me where to find, source of Qt Creator shortcut edit class grab ?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dridk
      wrote on last edited by
      #2

      Create a class which inherits from QLineEdit.
      And then , reimplement keyPressEvent()

      This is a quick exemple !
      @
      GrabLineEdit::GrabLineEdit(QWidget *parent) :
      QLineEdit(parent)
      {
      }

      void GrabLineEdit::keyPressEvent(QKeyEvent *event)
      {
      QString grab;
      switch ( event->modifiers())
      {
      case Qt::ShiftModifier : grab.append("Shift+");break;
      case Qt::ControlModifier : grab.append("Ctrl+");break;
      case Qt::AltModifier : grab.append("Alt+");break;
      }

          grab.append(event->text());
          setText(grab);
      
      // QLineEdit::keyPressEvent(event);
      

      }
      @

      Nothing in Biology Makes Sense Except in the Light of Evolution

      1 Reply Last reply
      0
      • M Offline
        M Offline
        maxvanceffer
        wrote on last edited by
        #3

        ho ho ))) great quick example... thx

        1 Reply Last reply
        0
        • M Offline
          M Offline
          maxvanceffer
          wrote on last edited by
          #4

          But some thing strange comes, when Ctrl pressed no key text
          returned by QKeyEvent::text()

          1 Reply Last reply
          0
          • M Offline
            M Offline
            MAD911
            wrote on last edited by
            #5

            solve problem with Ctrl and modify keyPressEvent function
            @
            void keyPressEvent(QKeyEvent *event)
            {
            QString grab;
            int modifiers = event->modifiers();
            if(modifiers & Qt::ControlModifier)
            grab.append("Ctrl+");
            if(modifiers & Qt::ShiftModifier)
            grab.append("Shift+");
            if(modifiers & Qt::AltModifier)
            grab.append("Alt+");
            grab.append(event->key());
            setText(grab);
            // QLineEdit::keyPressEvent(event);
            }
            @

            Edit: please use @ tags around code sections; Andre

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mbnoimi
              wrote on last edited by
              #6

              Sorry for digging it out :)

              Is there any way to solve this issue without inheriting QLineEdit?

              P.S. I already built my ui so reimplementing a new class will be hard to me.

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

                eventFilter comes to mind if you don't want to subclass

                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