diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index 9dde2c392ca..955f5cdfe35 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -49,6 +49,7 @@ #include #include #include +#include #include #include #include // for Qt::mightBeRichText @@ -927,4 +928,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 6aa65369fa6..5b32f03aaf8 100644 --- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -232,6 +233,18 @@ namespace GUIUtil typedef ClickableProgressBar ProgressBar; + 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