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.
  • Ramkumar MohanR Offline
    Ramkumar MohanR Offline
    Ramkumar Mohan
    wrote on 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.

    jsulmJ 1 Reply Last reply
    0
    • Ramkumar MohanR Ramkumar Mohan

      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.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on 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

      Ramkumar MohanR 1 Reply Last reply
      0
      • jsulmJ jsulm

        @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

        Ramkumar MohanR Offline
        Ramkumar MohanR Offline
        Ramkumar Mohan
        wrote on 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,

        jsulmJ 1 Reply Last reply
        0
        • Ramkumar MohanR Ramkumar Mohan

          @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,

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on 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

          Ramkumar MohanR 1 Reply Last reply
          0
          • jsulmJ jsulm

            @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...

            Ramkumar MohanR Offline
            Ramkumar MohanR Offline
            Ramkumar Mohan
            wrote on 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
            0
            • Ramkumar MohanR Ramkumar Mohan

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

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on 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?

              Ramkumar MohanR 1 Reply Last reply
              0
              • Ramkumar MohanR Ramkumar Mohan

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

                M Offline
                M Offline
                mpergand
                wrote on 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

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

                  Ramkumar MohanR Offline
                  Ramkumar MohanR Offline
                  Ramkumar Mohan
                  wrote on 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 jsulmJ 2 Replies Last reply
                  0
                  • Ramkumar MohanR Ramkumar Mohan

                    @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 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?

                    Ramkumar MohanR 1 Reply Last reply
                    0
                    • Ramkumar MohanR Ramkumar Mohan

                      @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.

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on 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

                        @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?

                        Ramkumar MohanR Offline
                        Ramkumar MohanR Offline
                        Ramkumar Mohan
                        wrote on last edited by
                        #11

                        @JonB

                        Now , code working fine sir ,
                        Thank you.

                        1 Reply Last reply
                        0
                        • M mpergand referenced this topic on

                        • Login

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