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
    #2

    Hi,

    Do you mean that you would like the whole original text to be selected when the line edit gets the focus so you can just past over it ?

    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
      #3

      No, because if I do this, there introduce an accessibility issue on Linux. It's why I want to use signals and slots.
      But right, select text when combo gets focus is working.

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

        Which accessibility issue ?

        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
          #5

          I've an history of latest lines in my combo, on Linux if I select text of current line, Orca has some difficulties to read lines.

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

            From the looks of it, you can't override paste.
            Maybe an event filter on the QShortCutEvent might do the trick when dealing with the Paste shortcut.

            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
              #7

              Do you mean something like this?
              void myModal::keyPressEvent(QKeyEvent* e)
              {
              ui.myCombo->lineEdit()::keyPressEvent(e);

              if(e->matches(QKeySequence::Paste))
              {
                  slotTxtChange();
              }
              

              }
              But how I can retrieve content to past to my function to delete current text and insert the newest?

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

                I would just call clear followed by 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
                0
                • O Offline
                  O Offline
                  Oreonan
                  wrote on last edited by
                  #9

                  QLineEdit has no function named paste, right?
                  Should I integrate another class?

                  1 Reply Last reply
                  0
                  • 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