Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Shortcut QLineEdit

    General and Desktop
    5
    7
    4567
    Loading More Posts
    • 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
      maxvanceffer last edited by

      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 Reply Quote 0
      • D
        dridk last edited by

        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 Reply Quote 0
        • M
          maxvanceffer last edited by

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

          1 Reply Last reply Reply Quote 0
          • M
            maxvanceffer last edited by

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

            1 Reply Last reply Reply Quote 0
            • M
              MAD911 last edited by

              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 Reply Quote 0
              • M
                mbnoimi last edited by

                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 Reply Quote 0
                • SGaist
                  SGaist Lifetime Qt Champion last edited by

                  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 Reply Quote 0
                  • First post
                    Last post