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 move from one Text Edit to another Text Edit by pressing the enter button.

How to move from one Text Edit to another Text Edit by pressing the enter button.

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 4 Posters 970 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.
  • R Offline
    R Offline
    Ramkumar Mohan
    wrote on 18 Oct 2022, 07:18 last edited by
    #1

    te.PNG

    How to move from one Text Edit to another Text Edit by pressing the enter button.

    li.PNG

    Values ​​can be added in text edit using enter button but for me press enter button then add only in next text edit. How to do.

    J 1 Reply Last reply 18 Oct 2022, 07:21
    0
    • R Ramkumar Mohan
      18 Oct 2022, 07:18

      te.PNG

      How to move from one Text Edit to another Text Edit by pressing the enter button.

      li.PNG

      Values ​​can be added in text edit using enter button but for me press enter button then add only in next text edit. How to do.

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 18 Oct 2022, 07:21 last edited by
      #2

      @Ramkumar-Mohan Install event filter in your test edit widgets and in case of enter key press move focus to next text edit widget.
      See "Event Filters" in https://doc.qt.io/qt-5/eventsandfilters.html

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      R 1 Reply Last reply 19 Oct 2022, 09:56
      0
      • J jsulm
        18 Oct 2022, 07:21

        @Ramkumar-Mohan Install event filter in your test edit widgets and in case of enter key press move focus to next text edit widget.
        See "Event Filters" in https://doc.qt.io/qt-5/eventsandfilters.html

        R Offline
        R Offline
        Ramkumar Mohan
        wrote on 19 Oct 2022, 09:56 last edited by Ramkumar Mohan
        #3

        @jsulm

        Hi ,

        I wrote this code ,

        MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
        {
        ui->setupUi(this);
        this->ui->textEdit->installEventFilter(this);
        this->ui->textEdit_2->installEventFilter(this);
        this->ui->textEdit_3->installEventFilter(this);
        this->ui->textEdit_4->installEventFilter(this);
        this->ui->textEdit_5->installEventFilter(this);
        }

        I use 5 TextEdit filed (textEdit , textEdit_2, textEdit_3, textEdit_4, textEdit_5).

        bool MainWindow::eventFilter(QObject *target, QEvent *event)
        {
        if(target != this->ui->textEdit)return false;

        if(event->type() == QEvent::KeyPress)
        {
            QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
            if(keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter)
            {
                qDebug() << "eventFilter Enter pressed-1";
                this->ui->textEdit_2->setFocus();
                return true;
            }
        }
        if(event->type() == QEvent::KeyRelease)
        {
            QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
            if(keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter)
            {
                qDebug() << "eventFilter Enter pressed released-1";
                return true;
            }
        }
        return false;
        

        }

        pic.PNG

        In this, if you put a value in a text edit and press the enter button, I have set the next value in another text box. Also I need to set values ​​in 5 text boxes then press enter button.
        how to do it,

        J 1 Reply Last reply 19 Oct 2022, 11:28
        0
        • R Ramkumar Mohan
          19 Oct 2022, 09:56

          @jsulm

          Hi ,

          I wrote this code ,

          MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::MainWindow)
          {
          ui->setupUi(this);
          this->ui->textEdit->installEventFilter(this);
          this->ui->textEdit_2->installEventFilter(this);
          this->ui->textEdit_3->installEventFilter(this);
          this->ui->textEdit_4->installEventFilter(this);
          this->ui->textEdit_5->installEventFilter(this);
          }

          I use 5 TextEdit filed (textEdit , textEdit_2, textEdit_3, textEdit_4, textEdit_5).

          bool MainWindow::eventFilter(QObject *target, QEvent *event)
          {
          if(target != this->ui->textEdit)return false;

          if(event->type() == QEvent::KeyPress)
          {
              QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
              if(keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter)
              {
                  qDebug() << "eventFilter Enter pressed-1";
                  this->ui->textEdit_2->setFocus();
                  return true;
              }
          }
          if(event->type() == QEvent::KeyRelease)
          {
              QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
              if(keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter)
              {
                  qDebug() << "eventFilter Enter pressed released-1";
                  return true;
              }
          }
          return false;
          

          }

          pic.PNG

          In this, if you put a value in a text edit and press the enter button, I have set the next value in another text box. Also I need to set values ​​in 5 text boxes then press enter button.
          how to do it,

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 19 Oct 2022, 11:28 last edited by
          #4

          @Ramkumar-Mohan said in How to move from one Text Edit to another Text Edit by pressing the enter button.:

          Also I need to set values ​​in 5 text boxes then press enter button

          Then do that. What exactly is the problem? in your event filter you can check which text edit has the focus and then you know which one should get the focus as next...

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          R 1 Reply Last reply 19 Oct 2022, 11:36
          0
          • J jsulm
            19 Oct 2022, 11:28

            @Ramkumar-Mohan said in How to move from one Text Edit to another Text Edit by pressing the enter button.:

            Also I need to set values ​​in 5 text boxes then press enter button

            Then do that. What exactly is the problem? in your event filter you can check which text edit has the focus and then you know which one should get the focus as next...

            R Offline
            R Offline
            Ramkumar Mohan
            wrote on 19 Oct 2022, 11:36 last edited by
            #5

            @jsulm
            First text edit 2 becomes focus. After that how to focus text editor-3.

            JonBJ M 2 Replies Last reply 19 Oct 2022, 12:06
            0
            • R Ramkumar Mohan
              19 Oct 2022, 11:36

              @jsulm
              First text edit 2 becomes focus. After that how to focus text editor-3.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on 19 Oct 2022, 12:06 last edited by
              #6

              @Ramkumar-Mohan
              Look at which text edit currently has the focus and set the focus to the next one based on that?

              R 1 Reply Last reply 19 Oct 2022, 16:32
              0
              • R Ramkumar Mohan
                19 Oct 2022, 11:36

                @jsulm
                First text edit 2 becomes focus. After that how to focus text editor-3.

                M Offline
                M Offline
                mpergand
                wrote on 19 Oct 2022, 12:57 last edited by
                #7

                @Ramkumar-Mohan

                On press release, set the focus to the next child (here line edits)

                class WindowFocus : public QWidget
                {
                    public:
                
                        explicit WindowFocus(QWidget* parent=nullptr) : QWidget(parent)
                        {
                            auto layout=new QVBoxLayout;
                            setLayout(layout);
                
                            for(int i=0; i<5; i++)
                                {
                                layout->addWidget(new QLineEdit);
                                }
                
                            installEventFilter(this);
                        }
                
                    bool eventFilter(QObject *obj, QEvent *event) override
                    {
                        QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
                
                        if( (keyEvent->key() == Qt::Key_Return ||
                             keyEvent->key() == Qt::Key_Enter) &&
                            keyEvent->type() == QEvent::KeyRelease)
                            {
                            QLineEdit* edit=qobject_cast<QLineEdit*>(focusWidget());
                            
                            if(edit)  // focus widget
                                {
                                QList<QLineEdit*> children=findChildren<QLineEdit*>();
                                int index=children.indexOf(edit); // index of current focused line edit
                
                                if(index!=-1 && (index+1<children.count()) )
                                    {
                                    children[index+1]->setFocus(); // next line edit
                                    }
                                }
                
                             return true;
                            }
                        return false;
                    }
                
                1 Reply Last reply
                3
                • JonBJ JonB
                  19 Oct 2022, 12:06

                  @Ramkumar-Mohan
                  Look at which text edit currently has the focus and set the focus to the next one based on that?

                  R Offline
                  R Offline
                  Ramkumar Mohan
                  wrote on 19 Oct 2022, 16:32 last edited by Ramkumar Mohan
                  #8

                  @JonB

                  bool MainWindow::eventFilter(QObject *target, QEvent *event)
                  {
                  if(target != this->ui->TextEdit)return false;

                  if(event->type() == QEvent::KeyPress)
                  {
                      QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
                      if(keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter)
                          {
                          qDebug() << "eventFilter Enter pressed";
                          return true;
                      }
                  }
                  if(event->type() == QEvent::KeyRelease)
                  {
                      QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
                      if(keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter)
                      {
                         ui->TextEdit_2->setFocus();
                        
                          qDebug() << "eventFilter Enter pressed released-2";
                  
                          return true;
                      }
                  }
                  
                  return false;
                  

                  }

                  Currently Textedit-2 is focus, I don't know how to focus next Textedit_3, tell me if there is a link for reference.

                  I have done text edit field 4 Drag and drop.

                  JonBJ J 2 Replies Last reply 19 Oct 2022, 17:26
                  0
                  • R Ramkumar Mohan
                    19 Oct 2022, 16:32

                    @JonB

                    bool MainWindow::eventFilter(QObject *target, QEvent *event)
                    {
                    if(target != this->ui->TextEdit)return false;

                    if(event->type() == QEvent::KeyPress)
                    {
                        QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
                        if(keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter)
                            {
                            qDebug() << "eventFilter Enter pressed";
                            return true;
                        }
                    }
                    if(event->type() == QEvent::KeyRelease)
                    {
                        QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
                        if(keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter)
                        {
                           ui->TextEdit_2->setFocus();
                          
                            qDebug() << "eventFilter Enter pressed released-2";
                    
                            return true;
                        }
                    }
                    
                    return false;
                    

                    }

                    Currently Textedit-2 is focus, I don't know how to focus next Textedit_3, tell me if there is a link for reference.

                    I have done text edit field 4 Drag and drop.

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on 19 Oct 2022, 17:26 last edited by
                    #9

                    @Ramkumar-Mohan
                    You have not tried to implement what I suggested. You're just showing the same code as you had before. There isn't a "link for reference".

                    @mpergand's code looks fine to me, why not use or adapt that?

                    R 1 Reply Last reply 20 Oct 2022, 06:00
                    0
                    • R Ramkumar Mohan
                      19 Oct 2022, 16:32

                      @JonB

                      bool MainWindow::eventFilter(QObject *target, QEvent *event)
                      {
                      if(target != this->ui->TextEdit)return false;

                      if(event->type() == QEvent::KeyPress)
                      {
                          QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
                          if(keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter)
                              {
                              qDebug() << "eventFilter Enter pressed";
                              return true;
                          }
                      }
                      if(event->type() == QEvent::KeyRelease)
                      {
                          QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
                          if(keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter)
                          {
                             ui->TextEdit_2->setFocus();
                            
                              qDebug() << "eventFilter Enter pressed released-2";
                      
                              return true;
                          }
                      }
                      
                      return false;
                      

                      }

                      Currently Textedit-2 is focus, I don't know how to focus next Textedit_3, tell me if there is a link for reference.

                      I have done text edit field 4 Drag and drop.

                      J Offline
                      J Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on 20 Oct 2022, 05:55 last edited by
                      #10

                      @Ramkumar-Mohan Did you actually read what I wrote before end tried to implement that? I wrote: "in your event filter you can check which text edit has the focus and then you know which one should get the focus as next"...

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • JonBJ JonB
                        19 Oct 2022, 17:26

                        @Ramkumar-Mohan
                        You have not tried to implement what I suggested. You're just showing the same code as you had before. There isn't a "link for reference".

                        @mpergand's code looks fine to me, why not use or adapt that?

                        R Offline
                        R Offline
                        Ramkumar Mohan
                        wrote on 20 Oct 2022, 06:00 last edited by
                        #11

                        @JonB

                        Now , code working fine sir ,
                        Thank you.

                        1 Reply Last reply
                        0
                        • M mpergand referenced this topic on 22 Feb 2023, 14:14

                        1/11

                        18 Oct 2022, 07:18

                        • Login

                        • Login or register to search.
                        1 out of 11
                        • First post
                          1/11
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved