1
0

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.
This commit is contained in:
SomberNight
2025-02-10 18:32:09 +00:00
parent 3de90952d1
commit 72c664856d
2 changed files with 9 additions and 7 deletions

View File

@@ -20,6 +20,8 @@ class QrCodeDataOverflow(qrcode.exceptions.DataOverflowError):
class QRCodeWidget(QWidget): 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): def __init__(self, data=None, *, manual_size: bool = False):
QWidget.__init__(self) QWidget.__init__(self)
self.data = None self.data = None
@@ -44,7 +46,8 @@ class QRCodeWidget(QWidget):
self.data = data self.data = data
if not self._manual_size: if not self._manual_size:
k = len(qr_matrix) k = len(qr_matrix)
self.setMinimumSize(k * 5, k * 5) size = min(k * 5, 150 + k * self.MIN_BOXSIZE)
self.setMinimumSize(size, size)
else: else:
self.qr = None self.qr = None
self.data = None self.data = None
@@ -79,9 +82,9 @@ class QRCodeWidget(QWidget):
framesize = min(r.width(), r.height()) framesize = min(r.width(), r.height())
self._framesize = framesize self._framesize = framesize
boxsize = int(framesize/(k + 2)) boxsize = int(framesize/(k + 2))
if boxsize < 2: if boxsize < self.MIN_BOXSIZE:
qp.drawText(0, 20, 'Cannot draw QR code:') qp.drawText(0, 20, _("Cannot draw QR code")+":")
qp.drawText(0, 40, 'Boxsize too small') qp.drawText(0, 40, _("Not enough space available. Try increasing the window size."))
qp.end() qp.end()
return return
size = k*boxsize size = k*boxsize
@@ -131,8 +134,7 @@ class QRDialog(WindowModalDialog):
vbox = QVBoxLayout() vbox = QVBoxLayout()
qrw = QRCodeWidget(data, manual_size=True) qrw = QRCodeWidget(data, manual_size=False)
qrw.setMinimumSize(250, 250)
vbox.addWidget(qrw, 1) vbox.addWidget(qrw, 1)
help_text = data if show_text else help_text help_text = data if show_text else help_text

View File

@@ -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. """ """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.""") """As a workaround, try exporting the tx as file or text instead.""")
try: 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: except qrcode.exceptions.DataOverflowError:
self.show_error(_('Failed to display QR code.') + '\n' + self.show_error(_('Failed to display QR code.') + '\n' +
_('Transaction is too large in size.')) _('Transaction is too large in size.'))