lincolnloop / python-qrcode

Python QR Code image generator
https://pypi.python.org/pypi/qrcode
Other
4.41k stars 676 forks source link

Why does my QR code look like diagonal lines? #120

Closed ghost closed 8 years ago

ghost commented 8 years ago

I'm creating the qr code and then trying to display it with PyQt4 by first using ImageQt, then QtGui.QPixmap.fromImage and lastly setPixmap. Some strings I give it result in normal qr codes with block and white boxes, but some result in black and white diagonal lines.

welshjf commented 8 years ago

You haven't given much info to go on here.

ghost commented 8 years ago

I'm using version 5.3 with Python 2.7.6. When I use the command line implementation to write out a PNG, the QR code looks normal. An example bad string is "This is just a test."

Here's my code sample:

qr = qrcode.QRCode ( version=None, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=10, boarder=4, ) qr.add_data("This is a test.") qr.make(fit=True) self.qr_code = qr.make_image()

self.qrBox = QtGui.QDialog() layout = QtGui.QGridLayout(self.qrBox) self.qr_image = QtGui.Label(self) qim = ImageQt(self.qr_code) self.qr_pixmap = QtGui.QPixmap.fromImage(qim) self.qr_image.setPixmap(self.qr_pixmap) layout.addWidget(self.qr_image,0,0,1,1) self.qrBox.show()

img_7711

kuhne commented 8 years ago

This is not a qrcode issue, you have to use QtGui.QImage.fromData.

Example (using segno, but qrcode should work analogously):

import io
from PySide import QtGui
import segno

app = QtGui.QApplication([])
out = io.BytesIO()
# Save PNG into "out"
segno.make('Bla bla bla bla').save(out, kind='png', scale=10)
out.seek(0)
label = QtGui.QLabel()
# Read PNG from "out"
qim = QtGui.QImage.fromData(out.getvalue())
qr_pixmap = QtGui.QPixmap.fromImage(qim)
label.setPixmap(qr_pixmap)
label.show()
label.raise_()
app.exec_()
ghost commented 8 years ago

Everything seems to be working correctly now, thanks for your help!