[PyQt] Need to draw rotating transparant image... without
flickering!
David Boddie
david at boddie.org.uk
Tue Jan 8 00:35:36 GMT 2008
On Sun, 30 Dec 2007 15:27:56 -0800 (PST), Wim wrote:
> 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):
[...]
> 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!
It's been a while since I looked at this kind of problem. Have you tried
experimenting with the updateEnabled property?
http://doc.trolltech.com/3.3/qwidget.html#updatesEnabled-prop
You could also try setting the WNoAutoErase flag on the widget:
http://doc.trolltech.com/3.3/qt.html#WidgetFlags-enum
The (C++) Qt 3 book contains an example of using bitBlt() to avoid flicker,
and there's an old Qt Quarterly article that might be relevant to you - if
you're comfortable with C++, though it should be readable even if you're
not:
http://doc.trolltech.com/qq/qq06-flicker-free.html
David
More information about the PyQt
mailing list