Skip to content

Commit 1c2a1ba

Browse files
committed
Add address label to request payment QR Code (QT)
In the Receive 'Tab' of the QT wallet, when 'Show'ing a previously requested payment, add a label underneath the QR Code showing the bitcoin address where the funds will go to. This way the user can be sure that the QR code scanner app the user using is reading the correct bitcoin address, preventing funds to be stolen. Includes fix for HiDPI screens by @jonasschnelli.
1 parent 44c1b1c commit 1c2a1ba

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

src/qt/forms/receiverequestdialog.ui

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<property name="minimumSize">
2323
<size>
2424
<width>300</width>
25-
<height>300</height>
25+
<height>320</height>
2626
</size>
2727
</property>
2828
<property name="toolTip">

src/qt/guiconstants.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static const int TOOLTIP_WRAP_THRESHOLD = 80;
4343
static const int MAX_URI_LENGTH = 255;
4444

4545
/* QRCodeDialog -- size of exported QR Code image */
46-
#define EXPORT_IMAGE_SIZE 256
46+
#define QR_IMAGE_SIZE 300
4747

4848
/* Number of frames in spinner animation */
4949
#define SPINNER_FRAMES 36

src/qt/receiverequestdialog.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ QImage QRImageWidget::exportImage()
4545
{
4646
if(!pixmap())
4747
return QImage();
48-
return pixmap()->toImage().scaled(EXPORT_IMAGE_SIZE, EXPORT_IMAGE_SIZE);
48+
return pixmap()->toImage();
4949
}
5050

5151
void QRImageWidget::mousePressEvent(QMouseEvent *event)
@@ -166,20 +166,32 @@ void ReceiveRequestDialog::update()
166166
ui->lblQRCode->setText(tr("Error encoding URI into QR Code."));
167167
return;
168168
}
169-
QImage myImage = QImage(code->width + 8, code->width + 8, QImage::Format_RGB32);
170-
myImage.fill(0xffffff);
169+
QImage qrImage = QImage(code->width + 8, code->width + 8, QImage::Format_RGB32);
170+
qrImage.fill(0xffffff);
171171
unsigned char *p = code->data;
172172
for (int y = 0; y < code->width; y++)
173173
{
174174
for (int x = 0; x < code->width; x++)
175175
{
176-
myImage.setPixel(x + 4, y + 4, ((*p & 1) ? 0x0 : 0xffffff));
176+
qrImage.setPixel(x + 4, y + 4, ((*p & 1) ? 0x0 : 0xffffff));
177177
p++;
178178
}
179179
}
180180
QRcode_free(code);
181181

182-
ui->lblQRCode->setPixmap(QPixmap::fromImage(myImage).scaled(300, 300));
182+
QImage qrAddrImage = QImage(QR_IMAGE_SIZE, QR_IMAGE_SIZE+20, QImage::Format_RGB32);
183+
qrAddrImage.fill(0xffffff);
184+
QPainter painter(&qrAddrImage);
185+
painter.drawImage(0, 0, qrImage.scaled(QR_IMAGE_SIZE, QR_IMAGE_SIZE));
186+
QFont font = GUIUtil::fixedPitchFont();
187+
font.setPixelSize(12);
188+
painter.setFont(font);
189+
QRect paddedRect = qrAddrImage.rect();
190+
paddedRect.setHeight(QR_IMAGE_SIZE+12);
191+
painter.drawText(paddedRect, Qt::AlignBottom|Qt::AlignCenter, info.address);
192+
painter.end();
193+
194+
ui->lblQRCode->setPixmap(QPixmap::fromImage(qrAddrImage));
183195
ui->btnSaveAs->setEnabled(true);
184196
}
185197
}

src/qt/receiverequestdialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <QDialog>
1111
#include <QImage>
1212
#include <QLabel>
13+
#include <QPainter>
1314

1415
class OptionsModel;
1516

0 commit comments

Comments
 (0)