diff options
author | Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> | 2020-08-23 23:53:17 +0300 |
---|---|---|
committer | Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> | 2020-09-07 15:49:37 +0300 |
commit | 6954156b4091bc1e561502f0eef0cece56c76eec (patch) | |
tree | 9320d39e4423810b9183c12268516fe3f873ffec /src/qt/qrimagewidget.cpp | |
parent | 8071c75d45e12c2bca04b170c687bebd30ad19ac (diff) |
qt: Fix visual quality of text in QR image
Diffstat (limited to 'src/qt/qrimagewidget.cpp')
-rw-r--r-- | src/qt/qrimagewidget.cpp | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/qt/qrimagewidget.cpp b/src/qt/qrimagewidget.cpp index de630b991b..52f1e60957 100644 --- a/src/qt/qrimagewidget.cpp +++ b/src/qt/qrimagewidget.cpp @@ -9,6 +9,7 @@ #include <QApplication> #include <QClipboard> #include <QDrag> +#include <QFontDatabase> #include <QMenu> #include <QMimeData> #include <QMouseEvent> @@ -64,24 +65,25 @@ bool QRImageWidget::setQR(const QString& data, const QString& text) } QRcode_free(code); - QImage qrAddrImage = QImage(QR_IMAGE_SIZE, QR_IMAGE_SIZE + (text.isEmpty() ? 0 : 20), QImage::Format_RGB32); + const int qr_image_size = QR_IMAGE_SIZE + (text.isEmpty() ? 0 : 2 * QR_IMAGE_MARGIN); + QImage qrAddrImage(qr_image_size, qr_image_size, QImage::Format_RGB32); qrAddrImage.fill(0xffffff); { QPainter painter(&qrAddrImage); - painter.drawImage(0, 0, qrImage.scaled(QR_IMAGE_SIZE, QR_IMAGE_SIZE)); + painter.drawImage(QR_IMAGE_MARGIN, 0, qrImage.scaled(QR_IMAGE_SIZE, QR_IMAGE_SIZE)); if (!text.isEmpty()) { - QFont font = GUIUtil::fixedPitchFont(); - font.setStyleStrategy(QFont::NoAntialias); QRect paddedRect = qrAddrImage.rect(); + paddedRect.setHeight(QR_IMAGE_SIZE + QR_IMAGE_TEXT_MARGIN); - // calculate ideal font size - qreal font_size = GUIUtil::calculateIdealFontSize(paddedRect.width() - 20, text, font); + QFont font = GUIUtil::fixedPitchFont(); + font.setStretch(QFont::SemiCondensed); + font.setLetterSpacing(QFont::AbsoluteSpacing, 1); + const qreal font_size = GUIUtil::calculateIdealFontSize(paddedRect.width() - 2 * QR_IMAGE_TEXT_MARGIN, text, font); font.setPointSizeF(font_size); painter.setFont(font); - paddedRect.setHeight(QR_IMAGE_SIZE+12); - painter.drawText(paddedRect, Qt::AlignBottom|Qt::AlignCenter, text); + painter.drawText(paddedRect, Qt::AlignBottom | Qt::AlignCenter, text); } } |