[PyQt] display QImage using QtPainter

Massimo Di Stefano massimodisasha at gmail.com
Wed Jan 5 15:41:06 GMT 2011


hello All,

i'm tring to use QtPainter to display a QImage object
this is my paint event : 


    def paintEvent(self, event):
        painter = QPainter(self)
        painter.fillRect(event.rect(), QBrush(Qt.black))
        image = self.receiver.getimage()
        print image , 'passed'
        imm = image.scaled(image.size(), Qt.KeepAspectRatio)
        immPos = QPoint((self.width() - image.width())/2.0,
(self.height() - image.height())/2.0)
        painter.drawImage(immPos, imm)


####

    self.cmp = QImage()
    def paintEvent(self, event):
        painter = QPainter(self)
        painter.fillRect(event.rect(), QBrush(Qt.black))
        image = self.receiver.getimage()
        print image , 'passed'
        self.cmp.load(image)
        cmp = self.cmp.scaled(self.size(), Qt.KeepAspectRatio)
        cmpPos = QPoint((self.width() - cmp.width())/2.0, (self.height()
- cmp.height())/2.0)
        painter.drawImage(cmpPos, cmp)


the first function receive a QImage object as event, but gived me a
segfault,

while the second function works .. 
but receive as event a "string" that's the full path to a real file.


Have you any hints on how to display a QImage object inside a QtPainter
event ?

thankyou for any hints!

Massimo.






More information about the PyQt mailing list