From 4c5143d56c98d4f9f961059692f155bbe2248c44 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Mon, 13 Dec 2021 06:19:49 +0000 Subject: [PATCH] GUI/QRImageWidget: Allow image to grow up to 25% wider to accomidate single-line text Accomidates addresses that are just barely too long for the QRCode width --- src/qt/qrimagewidget.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/qt/qrimagewidget.cpp b/src/qt/qrimagewidget.cpp index 7f955700d5..e8017cee54 100644 --- a/src/qt/qrimagewidget.cpp +++ b/src/qt/qrimagewidget.cpp @@ -83,7 +83,14 @@ bool QRImageWidget::setQR(const QString& data, const QString& text) // Plan how many lines are needed QFontMetrics fm(font); const int text_width = GUIUtil::TextWidth(fm, text); - text_lines = (text_width + max_text_width - 1) / max_text_width; + if (text_width > max_text_width && text_width < max_text_width * 5 / 4) { + // Allow the image to grow up to 25% wider + qr_image_width = text_width + (2 * QR_IMAGE_TEXT_MARGIN); + qr_image_x_margin = (qr_image_width - QR_IMAGE_SIZE) / 2; + text_lines = 1; + } else { + text_lines = (text_width + max_text_width - 1) / max_text_width; + } qr_image_height += (fm.height() * text_lines) + QR_IMAGE_TEXT_MARGIN; } QImage qrAddrImage(qr_image_width, qr_image_height, QImage::Format_RGB32);