From ea404445f6ef160f773417ed69999b141ef5dd02 Mon Sep 17 00:00:00 2001 From: silverqx Date: Wed, 23 May 2018 22:41:13 +0200 Subject: [PATCH] Clear LineEdit on ESC --- src/gui/lineedit/src/lineedit.cpp | 8 ++++++++ src/gui/lineedit/src/lineedit.h | 1 + 2 files changed, 9 insertions(+) diff --git a/src/gui/lineedit/src/lineedit.cpp b/src/gui/lineedit/src/lineedit.cpp index 0a900c625..5798bfcb9 100644 --- a/src/gui/lineedit/src/lineedit.cpp +++ b/src/gui/lineedit/src/lineedit.cpp @@ -40,3 +40,11 @@ void LineEdit::resizeEvent(QResizeEvent *e) const int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); m_searchButton->move(frameWidth, (e->size().height() - m_searchButton->sizeHint().height()) / 2); } + +void LineEdit::keyPressEvent(QKeyEvent *event) +{ + if ((event->modifiers() == Qt::NoModifier) && (event->key() == Qt::Key_Escape)) { + clear(); + } + QLineEdit::keyPressEvent(event); +} diff --git a/src/gui/lineedit/src/lineedit.h b/src/gui/lineedit/src/lineedit.h index 2d9440eb5..fcb16b60d 100644 --- a/src/gui/lineedit/src/lineedit.h +++ b/src/gui/lineedit/src/lineedit.h @@ -23,6 +23,7 @@ public: protected: void resizeEvent(QResizeEvent *e) override; + void keyPressEvent(QKeyEvent *event) override; private: QToolButton *m_searchButton;