Subclass QLineEdit
Reimplement keyPressEvent()
Catch Qt::Key_Enter
pressing and do your job or emit signal yourself
From documentation:
Qt::Key_Return 0x01000004
Qt::Key_Enter 0x01000005 Typically located on the keypad.
Something like this:
void LineEdit::keyPressEvent(QKeyEvent *event)
{
if(event->key() == Qt::Key_Enter)
{
//do something
}
}
If you do not want subclass, you can installEventFilter
to your dialog window, catch your lineEdit and check is Qt::Key_Enter
was pressed.
bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
if (obj == ui->lineEdit && event->type() == QEvent::KeyPress)
{
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
if(Qt::Key_Enter == keyEvent->key() )
{
qDebug() << "numpad Enter pressed";
}
}
}
Don't forget
protected:
bool eventFilter(QObject *obj, QEvent *event);//in header
and
qApp->installEventFilter(this);//in constructor
For example:
void MainWindow::on_lineEdit_returnPressed()
{
qDebug() << "numpad Enter pressed";
}