[PyKDE] Re: [PyQt3] Saving QPixmap onto a str

Mike Tammerman mtammerman at gmail.com
Tue Sep 5 09:56:59 BST 2006


Hi, I got it.

Someone may also need this. I am trying to serialize QPixmap to send
it over network. Here's the solution. Qt classes cannot be pickled.

------------
pixmap = ````This is a pixmap already in memory''''
buffer = QBuffer()
pixmap.save(buffer, 'XPM')
data = buffer.getData()
-----------

from qt import *
from cStringIO import StringIO

class QBuffer(QIODevice):

    def __init__(self):
        QIODevice.__init__(self)
        self.open( IO_ReadOnly)

    def open(self, mode):
        self.__io = StringIO()
        return True

    def close(self):
        self.__io.close()

    def flush(self):
        self.__io.flush()

    def readAll(self):
        return self.__io.read()

    def getch(self):
        return self.__io.read(1)

    def readBlock(self, size):
        result = self.__io.read(size)
        if result:
            return (result,)

        return None

    def writeBlock(self, data, length=None):
        if type(data) == QByteArray:
            data = data.data()

        self.__io.write(data)

        return len(data)

    def getData(self):
        return self.__io.getvalue()


On 9/4/06, Mike Tammerman <mtammerman at gmail.com> wrote:
> Hi,
>
> I am trying to save a QPixmap onto a str object. I tried using
> QBuffer. But QBuffer does not exist in pyqt3. I am using the kubuntu's
> default pyqt3 package which is 3.5.1. Sip version is 4.3.2.
>
> I don't want to use temporary files. Can you help me.
>
> Mike
>




More information about the PyQt mailing list