Browse Source

Merge pull request #8980 from silverqx/clear-on-esc

Clear LineEdit on ESC
adaptive-webui-19844
Vladimir Golovnev 6 years ago committed by GitHub
parent
commit
305c1fc851
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      src/gui/lineedit/src/lineedit.cpp
  2. 1
      src/gui/lineedit/src/lineedit.h

8
src/gui/lineedit/src/lineedit.cpp

@ -40,3 +40,11 @@ void LineEdit::resizeEvent(QResizeEvent *e) @@ -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);
}

1
src/gui/lineedit/src/lineedit.h

@ -23,6 +23,7 @@ public: @@ -23,6 +23,7 @@ public:
protected:
void resizeEvent(QResizeEvent *e) override;
void keyPressEvent(QKeyEvent *event) override;
private:
QToolButton *m_searchButton;

Loading…
Cancel
Save