11import qrcode
2- from PIL import ImageQt
2+
3+ from PyQt6 .QtGui import QImage , QColor , QPainter
4+ from PyQt6 .QtCore import Qt
35
46BLOCKS_URL = "https://blockstec.com"
57RF50_MANUAL_PAGE = "https://blockstec.com/RF50"
810RF50_USER_MANUAL_PAGE = "https://blockstec.com/assets/files/rf50_user_manual.pdf"
911
1012
11- def make_qrcode (data ) -> ImageQt . ImageQt :
12- """Generate a QR code image from *data* and return it as a Qt-compatible image ."""
13+ def make_qrcode (data : str ) -> QImage :
14+ """Generate a QR code image from *data* and return it as a QImage ."""
1315 qr = qrcode .QRCode (
1416 version = 1 ,
1517 error_correction = qrcode .ERROR_CORRECT_L ,
@@ -18,9 +20,25 @@ def make_qrcode(data) -> ImageQt.ImageQt:
1820 )
1921 qr .add_data (data )
2022 qr .make (fit = True )
21- img = qr .make_image (fill_color = "black" , back_color = "white" )
22- pil_image = img .get_image ()
23- return ImageQt .toqimage (pil_image )
23+
24+ matrix = qr .get_matrix ()
25+ box_size = 10
26+ size = len (matrix ) * box_size
27+
28+ image = QImage (size , size , QImage .Format .Format_RGB32 )
29+ image .fill (QColor ("white" ))
30+
31+ painter = QPainter (image )
32+ painter .setPen (Qt .PenStyle .NoPen )
33+ painter .setBrush (QColor ("black" ))
34+
35+ for y , row in enumerate (matrix ):
36+ for x , cell in enumerate (row ):
37+ if cell :
38+ painter .drawRect (x * box_size , y * box_size , box_size , box_size )
39+
40+ painter .end ()
41+ return image
2442
2543
2644_NM_TO_WIFI_QR_AUTH : dict [str , str ] = {
@@ -36,7 +54,7 @@ def make_qrcode(data) -> ImageQt.ImageQt:
3654
3755def generate_wifi_qrcode (
3856 ssid : str , password : str , auth_type : str , hidden : bool = False
39- ) -> ImageQt . ImageQt :
57+ ) -> QImage :
4058 """Build a Wi-Fi QR code for the given SSID/password/auth combination.
4159
4260 *auth_type* is a NetworkManager key-mgmt value (e.g. ``"wpa-psk"``,
0 commit comments