Skip to content

Commit a2e122f

Browse files
hebastojarolrod
andcommitted
qt: Add GUIUtil::AddButtonShortcut
Co-authored-by: Jarol Rodriguez <[email protected]>
1 parent 4ee9ee7 commit a2e122f

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/qt/guiutil.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <shlwapi.h>
3030
#endif
3131

32+
#include <QAbstractButton>
3233
#include <QAbstractItemView>
3334
#include <QApplication>
3435
#include <QClipboard>
@@ -119,6 +120,11 @@ void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent)
119120
widget->setCheckValidator(new BitcoinAddressCheckValidator(parent));
120121
}
121122

123+
void AddButtonShortcut(QAbstractButton* button, const QKeySequence& shortcut)
124+
{
125+
QObject::connect(new QShortcut(shortcut, button), &QShortcut::activated, [button]() { button->animateClick(); });
126+
}
127+
122128
bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out)
123129
{
124130
// return if URI is not valid or is no bitcoin: URI

src/qt/guiutil.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ namespace interfaces
3131
}
3232

3333
QT_BEGIN_NAMESPACE
34+
class QAbstractButton;
3435
class QAbstractItemView;
3536
class QAction;
3637
class QDateTime;
3738
class QFont;
39+
class QKeySequence;
3840
class QLineEdit;
3941
class QMenu;
4042
class QPoint;
@@ -60,6 +62,14 @@ namespace GUIUtil
6062
// Set up widget for address
6163
void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent);
6264

65+
/**
66+
* Connects an additional shortcut to a QAbstractButton. Works around the
67+
* one shortcut limitation of the button's shortcut property.
68+
* @param[in] button QAbstractButton to assign shortcut to
69+
* @param[in] shortcut QKeySequence to use as shortcut
70+
*/
71+
void AddButtonShortcut(QAbstractButton* button, const QKeySequence& shortcut);
72+
6373
// Parse "bitcoin:" URI into recipient object, return true on successful parsing
6474
bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out);
6575
bool parseBitcoinURI(QString uri, SendCoinsRecipient *out);

0 commit comments

Comments
 (0)