diff options
author | Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> | 2020-08-23 23:47:09 +0300 |
---|---|---|
committer | Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> | 2020-08-23 23:47:09 +0300 |
commit | 8071c75d45e12c2bca04b170c687bebd30ad19ac (patch) | |
tree | 595eb2306335b4f63932e7a34fa0bf2ba56a5906 | |
parent | 197450f80868fe752c6107955e5da80704212b34 (diff) |
qt, refactor: Limit scope of QPainter object
-rw-r--r-- | src/qt/qrimagewidget.cpp | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/src/qt/qrimagewidget.cpp b/src/qt/qrimagewidget.cpp index c816e1f8ed..de630b991b 100644 --- a/src/qt/qrimagewidget.cpp +++ b/src/qt/qrimagewidget.cpp @@ -66,24 +66,25 @@ bool QRImageWidget::setQR(const QString& data, const QString& text) QImage qrAddrImage = QImage(QR_IMAGE_SIZE, QR_IMAGE_SIZE + (text.isEmpty() ? 0 : 20), QImage::Format_RGB32); qrAddrImage.fill(0xffffff); - QPainter painter(&qrAddrImage); - painter.drawImage(0, 0, qrImage.scaled(QR_IMAGE_SIZE, QR_IMAGE_SIZE)); + { + QPainter painter(&qrAddrImage); + painter.drawImage(0, 0, qrImage.scaled(QR_IMAGE_SIZE, QR_IMAGE_SIZE)); - if (!text.isEmpty()) { - QFont font = GUIUtil::fixedPitchFont(); - font.setStyleStrategy(QFont::NoAntialias); - QRect paddedRect = qrAddrImage.rect(); + if (!text.isEmpty()) { + QFont font = GUIUtil::fixedPitchFont(); + font.setStyleStrategy(QFont::NoAntialias); + QRect paddedRect = qrAddrImage.rect(); - // calculate ideal font size - qreal font_size = GUIUtil::calculateIdealFontSize(paddedRect.width() - 20, text, font); - font.setPointSizeF(font_size); + // calculate ideal font size + qreal font_size = GUIUtil::calculateIdealFontSize(paddedRect.width() - 20, text, font); + font.setPointSizeF(font_size); - painter.setFont(font); - paddedRect.setHeight(QR_IMAGE_SIZE+12); - painter.drawText(paddedRect, Qt::AlignBottom|Qt::AlignCenter, text); + painter.setFont(font); + paddedRect.setHeight(QR_IMAGE_SIZE+12); + painter.drawText(paddedRect, Qt::AlignBottom|Qt::AlignCenter, text); + } } - painter.end(); setPixmap(QPixmap::fromImage(qrAddrImage)); return true; |