From 72c664856d9654e8b29a90ef82a1d90a6d5b3899 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Mon, 10 Feb 2025 18:32:09 +0000 Subject: [PATCH] qt gui: qrcodewidget: default size smaller for large codes and use default sizing when displaying PSBTs. Prior to this, when displaying a large PSBT (that should still fit within a QR), the default window size was too small, and the user had to manually resize the window. --- electrum/gui/qt/qrcodewidget.py | 14 ++++++++------ electrum/gui/qt/transaction_dialog.py | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/electrum/gui/qt/qrcodewidget.py b/electrum/gui/qt/qrcodewidget.py index 33e1d8d56..d1fa4bb07 100644 --- a/electrum/gui/qt/qrcodewidget.py +++ b/electrum/gui/qt/qrcodewidget.py @@ -20,6 +20,8 @@ class QrCodeDataOverflow(qrcode.exceptions.DataOverflowError): class QRCodeWidget(QWidget): + MIN_BOXSIZE = 2 # min size in pixels of single black/white unit box of the qr code + def __init__(self, data=None, *, manual_size: bool = False): QWidget.__init__(self) self.data = None @@ -44,7 +46,8 @@ class QRCodeWidget(QWidget): self.data = data if not self._manual_size: k = len(qr_matrix) - self.setMinimumSize(k * 5, k * 5) + size = min(k * 5, 150 + k * self.MIN_BOXSIZE) + self.setMinimumSize(size, size) else: self.qr = None self.data = None @@ -79,9 +82,9 @@ class QRCodeWidget(QWidget): framesize = min(r.width(), r.height()) self._framesize = framesize boxsize = int(framesize/(k + 2)) - if boxsize < 2: - qp.drawText(0, 20, 'Cannot draw QR code:') - qp.drawText(0, 40, 'Boxsize too small') + if boxsize < self.MIN_BOXSIZE: + qp.drawText(0, 20, _("Cannot draw QR code")+":") + qp.drawText(0, 40, _("Not enough space available. Try increasing the window size.")) qp.end() return size = k*boxsize @@ -131,8 +134,7 @@ class QRDialog(WindowModalDialog): vbox = QVBoxLayout() - qrw = QRCodeWidget(data, manual_size=True) - qrw.setMinimumSize(250, 250) + qrw = QRCodeWidget(data, manual_size=False) vbox.addWidget(qrw, 1) help_text = data if show_text else help_text diff --git a/electrum/gui/qt/transaction_dialog.py b/electrum/gui/qt/transaction_dialog.py index c33e82be1..8830779ce 100644 --- a/electrum/gui/qt/transaction_dialog.py +++ b/electrum/gui/qt/transaction_dialog.py @@ -668,7 +668,7 @@ class TxDialog(QDialog, MessageBoxMixin): """out of the QR code as it would not fit. This might cause issues if signing offline. """ """As a workaround, try exporting the tx as file or text instead.""") try: - self.main_window.show_qrcode(qr_data, 'Transaction', parent=self, help_text=help_text) + self.main_window.show_qrcode(qr_data, _("Transaction"), parent=self, help_text=help_text) except qrcode.exceptions.DataOverflowError: self.show_error(_('Failed to display QR code.') + '\n' + _('Transaction is too large in size.'))