diff --git a/src/frontends/qt/GuiDocument.cpp b/src/frontends/qt/GuiDocument.cpp index 76b08132b3..287c0e8d74 100644 --- a/src/frontends/qt/GuiDocument.cpp +++ b/src/frontends/qt/GuiDocument.cpp @@ -481,6 +481,8 @@ PreambleModule::PreambleModule(QWidget * parent) preambleTE->setFont(guiApp->typewriterSystemFont()); preambleTE->setWordWrapMode(QTextOption::NoWrap); setFocusProxy(preambleTE); + // Install event filter on find line edit to capture return/enter key + findLE->installEventFilter(this); connect(preambleTE, SIGNAL(textChanged()), this, SIGNAL(changed())); connect(findLE, SIGNAL(textEdited(const QString &)), this, SLOT(checkFindButton())); connect(findButtonPB, SIGNAL(clicked()), this, SLOT(findText())); @@ -499,6 +501,23 @@ PreambleModule::PreambleModule(QWidget * parent) } +bool PreambleModule::eventFilter(QObject * sender, QEvent * event) +{ + if (sender == findLE) { + if (event->type()==QEvent::KeyPress) { + QKeyEvent * key = static_cast(event); + if ( (key->key()==Qt::Key_Enter) || (key->key()==Qt::Key_Return) ) { + findText(); + // Return true to filter out the event + return true; + } + } + } + return QWidget::eventFilter(sender, event); +} + + + void PreambleModule::checkFindButton() { findButtonPB->setEnabled(!findLE->text().isEmpty()); diff --git a/src/frontends/qt/GuiDocument.h b/src/frontends/qt/GuiDocument.h index ef143ab638..a5dfdfc5a3 100644 --- a/src/frontends/qt/GuiDocument.h +++ b/src/frontends/qt/GuiDocument.h @@ -373,6 +373,9 @@ Q_SIGNALS: /// signal that something's changed in the Widget. void changed(); +protected: + bool eventFilter(QObject * sender, QEvent * event); + private: void closeEvent(QCloseEvent *) override; void on_preambleTE_textChanged() { changed(); } diff --git a/src/frontends/qt/ui/PreambleUi.ui b/src/frontends/qt/ui/PreambleUi.ui index fd66051ce8..eb27e91adb 100644 --- a/src/frontends/qt/ui/PreambleUi.ui +++ b/src/frontends/qt/ui/PreambleUi.ui @@ -30,7 +30,11 @@ 6 - + + + Find in preamble + +