PySide compared to PyQt4 : problem with QImage __init__()

  • Hello,

    I'm trying to create a pyside backend for matplotlib by modifying the qt4agg backend.
    Now i'm stuck with a QImage problem :

    In PyQt4 the syntax is :

    img = QtGui.QImage(stringBuffer, 640,480,QtGui.QImage.Format_ARGB32)

    But converting to PySide raise an error because no init method accept these inputs (because of stringBuffer data).
    I tried with the staticmethod QImage.fromData(stringBuffer) but it does not work.

    I don't understand why pyside does not have the QImage ( uchar * data, int width, int height, Format format ) constructor ??

    Could someone help me on this topic ?
    How can i have the same result with a pyside syntax ?


  • Hi,

    This is a bug in PySide - see:

    Add yourself as a CC to the bug to get automatic updates about its progress.

    Due to the bug backlog we have, it might take a month or so before we have time to fix that, though. :-(

    Anyway, it's utterly cool that you're working on a matplotlib backend! I've really used matplotlib a lot for different kinds of projects of my own, and have always found the visual quality quite unmatched!


  • OK, thanks for the reply.
    Is there any way to get it working with methods like fromData or loadFromData ?

  • I haven't tested it myself, but according to the documentation, loadFromData should do exactly what you want. If it doesn't, it's a bug that should really be reported.

  • I think i don't use it properly because with PyQt and the following code :

    from PyQt4 import QtGui

    fid = open('/tmp/buffer.out','r')
    stringBuffer =

    img1 = QtGui.QImage(640,440, QtGui.QImage.Format_ARGB32)

    --> this make an empty png file*

    img2 = QtGui.QImage(stringBuffer,640,440, QtGui.QImage.Format_ARGB32)'test_pyqt4_2.png',format='png')

    --> this make a good png file with my figure

    Any idea how to use loadFromData in the good way so that i can reproduce with pyside??

Log in to reply