diff --git a/src/qt/editaddressdialog.cpp b/src/qt/editaddressdialog.cpp index 4528adc1c9..d2f18ebfe0 100644 --- a/src/qt/editaddressdialog.cpp +++ b/src/qt/editaddressdialog.cpp @@ -41,6 +41,10 @@ EditAddressDialog::EditAddressDialog(Mode _mode, QWidget *parent) : mapper = new QDataWidgetMapper(this); mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit); + + GUIUtil::ItemDelegate* delegate = new GUIUtil::ItemDelegate(mapper); + connect(delegate, &GUIUtil::ItemDelegate::keyEscapePressed, this, &EditAddressDialog::reject); + mapper->setItemDelegate(delegate); } EditAddressDialog::~EditAddressDialog() diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index e53c4c8cad..5768d8df66 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -1880,4 +1880,14 @@ void ClickableProgressBar::mouseReleaseEvent(QMouseEvent *event) Q_EMIT clicked(event->pos()); } +bool ItemDelegate::eventFilter(QObject *object, QEvent *event) +{ + if (event->type() == QEvent::KeyPress) { + if (static_cast(event)->key() == Qt::Key_Escape) { + Q_EMIT keyEscapePressed(); + } + } + return QItemDelegate::eventFilter(object, event); +} + } // namespace GUIUtil diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h index c0ed04d196..89f5c2792b 100644 --- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -424,6 +425,18 @@ namespace GUIUtil typedef ClickableProgressBar ProgressBar; #endif + class ItemDelegate : public QItemDelegate + { + Q_OBJECT + public: + ItemDelegate(QObject* parent) : QItemDelegate(parent) {} + + Q_SIGNALS: + void keyEscapePressed(); + + private: + bool eventFilter(QObject *object, QEvent *event); + }; } // namespace GUIUtil #endif // BITCOIN_QT_GUIUTIL_H diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp index b28919aece..46484aa141 100644 --- a/src/qt/optionsdialog.cpp +++ b/src/qt/optionsdialog.cpp @@ -136,6 +136,10 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) : mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit); mapper->setOrientation(Qt::Vertical); + GUIUtil::ItemDelegate* delegate = new GUIUtil::ItemDelegate(mapper); + connect(delegate, &GUIUtil::ItemDelegate::keyEscapePressed, this, &OptionsDialog::reject); + mapper->setItemDelegate(delegate); + /* setup/change UI elements when proxy IPs are invalid/valid */ ui->proxyIp->setCheckValidator(new ProxyAddressValidator(parent)); ui->proxyIpTor->setCheckValidator(new ProxyAddressValidator(parent));