[PyQt] Need to draw rotating transparant image... without flickering!

Wim_ wim12 at telenet.be
Sun Dec 30 23:27:56 GMT 2007


Hello,

This is what I would like to do (simplified): I have 2 images (dome.png,
telescope.png) which are 100x100px, transparant and are meant to be painted
on top of each other, each rotated under a certain angle. These 2 angles can
vary with time, and I would like the painting on the screen to be updated
with these new angles, say at a frequency of once per second.


My solution (simplified):



class Painting(QWidget):

    def __init__(self, *args):
        self.domeAngle = 0
        self.telescopeAngle = 0
        apply(QWidget.__init__,(self, ) + args)
        self.buffer = QPixmap()
        
        self.setGeometry(0,0,100,100)
        self.domeimage = QImage("dome.png")
        self.telescopeimage = QImage("telescope.png")

    def updateAngles(self,dome=None,telescope=None):
        if dome: self.domeAngle = dome
        if telescope: self.telescopeAngle = telescope
        self.update()

    def paintEvent(self, ev):
        p = QPainter()
        p.begin(self.buffer)
        p.translate(50,50)

        p.save()
        p.rotate(self.telescopeAngle)
        p.drawImage(QRect(-205,-205,410,410),self.telescopeimage)
        p.restore()
        
        p.save()
        p.rotate(self.domeAngle)
        p.drawImage(QRect(-205,-205,410,410),self.domeimage)
        p.restore()

        p.flush()
        p.end()
        bitBlt(self, 0, 0, self.buffer)


It works, but the problem is that it flickers! The current displayed
painting is "removed" at the first drawImage, and it takes until the bitBlt
before it is painted again! I have been trying a lot of other possibilities,
but they either give the same result, or strange "xlib" errors. The
environment where the code will run forces me to stick to QT3 so I hope it's
possible! 


If anyone could help me with this I would be very very grateful, thank you
very much!

Wim (from Belgium)

-- 
View this message in context: http://www.nabble.com/Need-to-draw-rotating-transparant-image...-without-flickering%21-tp14552438p14552438.html
Sent from the PyQt mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20071230/d2e3eeb6/attachment.html


More information about the PyQt mailing list