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. QLineEdit - Delete text when inserting another one
Forum Updated to NodeBB v4.3 + New Features

QLineEdit - Delete text when inserting another one

Scheduled Pinned Locked Moved Solved General and Desktop
19 Posts 2 Posters 1.3k 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #10

    Sure it does: QLineEdit::paste

    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
    1
    • O Offline
      O Offline
      Oreonan
      wrote on last edited by
      #11

      Oh yes sorry.
      So I made the following:
      void myModal::keyPressEvent(QKeyEvent* e)
      {
      if(e->matches(QKeySequence::Paste))
      {
      ui.myCombo->lineEdit()->clear();
      ui.myCombo->lineEdit()->paste();
      }
      }
      But I get the following error:
      error: invalid use of incomplete type 'class QKeyEvent'
      if(e->matches(QKeySequence::Paste))
      ^~
      sorry I'm not very good at handling QKeyEvent

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

        You did not include the corresponding header.

        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
        1
        • O Offline
          O Offline
          Oreonan
          wrote on last edited by
          #13

          Oh, yes, right.
          Latest thing, now it's working, but all other keys are without any effect.
          What should I add to let QT use other keys as expected?

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

            Call the base class implementation for all the other cases.

            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
            1
            • O Offline
              O Offline
              Oreonan
              wrote on last edited by
              #15

              Oh it was note latest thing :), so now I have this line added after my condition:
              QLineEdit::keyPressEvent(e);
              but I give the following error:
              error: cannot call member function 'virtual void QLineEdit::keyPressEvent(QKeyEvent*)' without object

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

                You cannot call the base class implementation of a different class.

                Note that I suggested to use an event filter not to override the keyPressEvent of a different class.

                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
                • O Offline
                  O Offline
                  Oreonan
                  wrote on last edited by
                  #17

                  OK I understood. So I made this:
                  bool myModal::eventFilter(QObject *object, QEvent *event)
                  {
                  if (object == ui.myCombo->lineEdit() && event->type() == QEvent::KeyPress) {
                  QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
                  if (keyEvent->matches(QKeySequence::Paste))
                  {
                  ui.myCombo->lineEdit()->clear();
                  ui.myCombo->lineEdit()->paste();
                  return true;
                  } else
                  return false;
                  }
                  return false;
                  }

                  but I still have to press CTRL+V twice to have this code works as expected :(

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

                    What if you just call clear and then return false ?

                    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
                    • O Offline
                      O Offline
                      Oreonan
                      wrote on last edited by
                      #19

                      I found. It's working without the ->lineEdit() after ui.myCombo.
                      Thanks for your help.

                      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