[PyQt] QPixmap.loadFromData()

Hans-Peter Jansen hpj at urpla.net
Mon Jan 28 14:11:32 GMT 2013


Am Freitag, 25. Januar 2013, 00:41:04 schrieb paolo at paolodestefani.it:
> 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"))

try this:

               print("Load", pix.loadFromData(QByteArray(ba), "PNG"))

Cheers,
Pete

>              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 ?
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt


More information about the PyQt mailing list