[PyQt] QPixmap.loadFromData()
paolo at paolodestefani.it
paolo at paolodestefani.it
Thu Jan 24 23:41:04 GMT 2013
Hello
I'm trying to create a item delegate for a sql table (postgres db)
where i have a field (type bytea) that should contain a PNG image.
This is the code of the create editor method:
def createEditor(self, parent, option, index):
dd = DisplayDialog(parent)
ba = index.model().data(index, Qt.DisplayRole)
if ba:
pix=QPixmap()
print("Load", pix.loadFromData(ba, "PNG"))
dd.lbimage.setPixmap(pix)
if dd.exec_() == QDialog.Accepted:
pix=dd.getImage()
ba = QByteArray()
buf = QBuffer(ba)
buf.open(QIODevice.WriteOnly)
print("Save", pix.save(buf, "PNG"))
index.model().setData(index, ba, Qt.EditRole)
index.model().submit()
I want that when te user click in the cell that will contain the PNG
image and a dialog popup where a can choose an PNG image file. This
dialog have a label that i used for displaying the image (dd.lbimage)
But when i test this i see:
Load False
Save True
which means (i guess) tha i can store the image in the db converting it
from PNG to QByteArray but when i retrieve it a can not convert from
QByteArray to PNG image.
What's wrong in my code ?
More information about the PyQt
mailing list