Pyqt: How to use QPixmap.loadFromData?
<p><a href="https://stackoverflow.com/questions/11210884/better-way-to-load-qpixmap-data">THIS link</a> describes a way to set a QPixmap without using QImage.
How can I reproduce this in python?</p>

<p>what I have is a buffer, which represents an image.</p>

<p>what I need is to call something like</p>

<pre><code>label.setPixmap(QPixmap.loadFromData(buffer))
</code></pre>

<p>to display the image.
But before that, a  format header has to be inserted, according to the link for a 300x300 grayscale image the header is something like "P6 300 300 255". I have no idea how to do that.</p>

<p>Here is the whole script:</p>

<pre><code>import numpy as np
import cv2
import sys
from PySide.QtGui import QApplication,QLabel,QPixmap


if QApplication.instance() is not None:
    a=QApplication.instance()
else: 
    a = QApplication(sys.argv)

lbl=QLabel()    
header = bytearray(b"P6 20 20 255")
cvImg=np.zeros((20,20),dtype=np.uint8)
cv2.circle(cvImg,(9,9),9,49,-1)
buff=cvImg.data
ppm=header+buff
pixmap=QPixmap()
lbl.setPixmap(pixmap.loadFromData(ppm,40,format="PPM"))


sys.exit(a.exec_())
</code></pre>

<p>It says:</p>

<pre><code>TypeError: 'PySide.QtGui.QPixmap.loadFromData' called with wrong argument types:
  PySide.QtGui.QPixmap.loadFromData(bytearray, int, str)
Supported signatures:
  PySide.QtGui.QPixmap.loadFromData(PySide.QtCore.QByteArray, str = None, PySide.QtCore.Qt.ImageConversionFlags = Qt.AutoColor)
  PySide.QtGui.QPixmap.loadFromData(PySide.QtCore.uchar, unsigned int, str = None, PySide.QtCore.Qt.ImageConversionFlags = Qt.AutoColor)
</code></pre>