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

Clear LineEdit on ESC
This commit is contained in:
Vladimir Golovnev 2018-10-11 17:31:38 +03:00 committed by GitHub
commit 305c1fc851
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View File

@ -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);
}

View File

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