Skip to content

Commit

Permalink
Fix bug when redrawing the qr code multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
Max-7 committed Jun 21, 2021
1 parent 467f371 commit d8f7d9c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion parsec/core/gui/custom_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def leaveEvent(self, event):
self._draw_overlay()

def setPixmap(self, pix):
self._pix = pix
self._pix = pix.copy()
self._draw_overlay()

def _draw_overlay(self):
Expand Down
14 changes: 8 additions & 6 deletions parsec/core/gui/qrcode_widget.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Parsec Cloud (https://parsec.cloud) Copyright (c) AGPLv3 2019 Scille SAS
# Parsec Cloud (https://parsec.cloud) Copyright (c) AGPLv3 2016-2021 Scille SAS

from PyQt5.QtCore import QRectF
from PyQt5.QtWidgets import QWidget, QVBoxLayout
Expand Down Expand Up @@ -27,13 +27,14 @@ def generate_qr_code(text):
img = QImage(":/logos/images/logos/parsec2.png")
if img:
img = img.convertToFormat(QImage.Format_ARGB32)
PARSEC_LOGO = QImage(img.width() + 30, img.height() + 20, QImage.Format_ARGB32)
PARSEC_LOGO.fill(QColor(0xF4, 0xF4, 0xF4))
logo = QImage(img.width() + 30, img.height() + 20, QImage.Format_ARGB32)
logo.fill(QColor(0xF4, 0xF4, 0xF4))
painter = QPainter()
painter.begin(PARSEC_LOGO)
painter.begin(logo)
painter.setCompositionMode(QPainter.CompositionMode_SourceOver)
painter.drawImage(15, 10, img)
painter.end()
PARSEC_LOGO = logo

qr = qrcode.QRCode(
version=None, error_correction=qrcode.constants.ERROR_CORRECT_H, border=4, box_size=10
Expand All @@ -46,13 +47,14 @@ def generate_qr_code(text):
qrcode.image.svg.SvgPathImage.QR_PATH_STYLE = (
"fill:#5193FF;fill-opacity:1;fill-rule:nonzero;stroke:none"
)
img = qr.make_image(image_factory=qrcode.image.svg.SvgPathImage)
qr_img = qr.make_image(image_factory=qrcode.image.svg.SvgPathImage)
stream = io.BytesIO()
img.save(stream)
qr_img.save(stream)
renderer = QSvgRenderer()
renderer.load(stream.getvalue())

final_img = QImage(600, 600, QImage.Format_ARGB32)
final_img.fill(QColor(0xF4, 0xF4, 0xF4))

painter = QPainter()
painter.begin(final_img)
Expand Down

0 comments on commit d8f7d9c

Please sign in to comment.