From 300a41c149efa7334f151f663e497cf9b21e992e Mon Sep 17 00:00:00 2001 From: BigBahss Date: Fri, 13 Nov 2020 02:52:37 -0500 Subject: [PATCH] Add clear button to MultiKeyEdit --- include/ui/multikeyedit.h | 2 ++ src/ui/multikeyedit.cpp | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/include/ui/multikeyedit.h b/include/ui/multikeyedit.h index c1736280..27231330 100644 --- a/include/ui/multikeyedit.h +++ b/include/ui/multikeyedit.h @@ -23,6 +23,8 @@ public: bool removeOne(const QKeySequence &keySequence); bool contains(const QKeySequence &keySequence) const; void setContextMenuPolicy(Qt::ContextMenuPolicy policy); + bool isClearButtonEnabled() const; + void setClearButtonEnabled(bool enable); public slots: void clear(); diff --git a/src/ui/multikeyedit.cpp b/src/ui/multikeyedit.cpp index 34ac19c8..09943861 100644 --- a/src/ui/multikeyedit.cpp +++ b/src/ui/multikeyedit.cpp @@ -98,6 +98,15 @@ void MultiKeyEdit::setContextMenuPolicy(Qt::ContextMenuPolicy policy) { lineEdit->setContextMenuPolicy(policy); } +bool MultiKeyEdit::isClearButtonEnabled() const { + return findChild()->isClearButtonEnabled(); +} + +void MultiKeyEdit::setClearButtonEnabled(bool enable) { + for (auto *lineEdit : findChildren()) + lineEdit->setClearButtonEnabled(enable); +} + void MultiKeyEdit::clear() { for (auto *keySequenceEdit : keySequenceEdit_vec) keySequenceEdit->clear(); @@ -126,6 +135,7 @@ void MultiKeyEdit::addNewKeySequenceEdit() { this, &MultiKeyEdit::keySequenceChanged); auto *lineEdit = keySequenceEdit->findChild(); + lineEdit->setClearButtonEnabled(true); lineEdit->installEventFilter(this); connect(lineEdit, &QLineEdit::customContextMenuRequested, this, &MultiKeyEdit::customContextMenuRequested);