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.
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.
-
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.htmlHi ,
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...
@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.@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.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; }
-
@Ramkumar-Mohan
Look at which text edit currently has the focus and set the focus to the next one based on 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.
-
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.
-
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?
Now , code working fine sir ,
Thank you. -