How to move from one Text Edit to another Text Edit by pressing the enter button.
-
wrote on 18 Oct 2022, 07:18 last edited by
-
How to move from one Text Edit to another Text Edit by pressing the enter button.
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.
@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-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.htmlwrote on 19 Oct 2022, 09:56 last edited by Ramkumar MohanHi ,
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;
}
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, -
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;
}
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,@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-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...
wrote on 19 Oct 2022, 11:36 last edited by@jsulm
First text edit 2 becomes focus. After that how to focus text editor-3. -
@jsulm
First text edit 2 becomes focus. After that how to focus text editor-3.wrote on 19 Oct 2022, 12:06 last edited by@Ramkumar-Mohan
Look at which text edit currently has the focus and set the focus to the next one based on that? -
@jsulm
First text edit 2 becomes focus. After that how to focus text editor-3.wrote on 19 Oct 2022, 12:57 last edited byOn 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; }
-
@Ramkumar-Mohan
Look at which text edit currently has the focus and set the focus to the next one based on that?wrote on 19 Oct 2022, 16:32 last edited by Ramkumar Mohanbool 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.
-
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.
wrote on 19 Oct 2022, 17:26 last edited by@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?
-
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.
@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"...
-
@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?
wrote on 20 Oct 2022, 06:00 last edited byNow , code working fine sir ,
Thank you. -
1/11