From kde-devel Thu Nov 30 17:31:32 2006 From: Matt Newell Date: Thu, 30 Nov 2006 17:31:32 +0000 To: kde-devel Subject: Re: Animation with QPainter Message-Id: <200611300931.33004.newellm () blur ! com> X-MARC-Message: https://marc.info/?l=kde-devel&m=116490813905480 On Thursday 30 November 2006 08:45, Matej Svejda wrote: > Hi! > > I want to include an animation in my program (a metronome for KDE 3.5). I > used QPainter for painting and QTimer for the animation. > What bothers me is that the animation just isn't smooth. First I directly > painted via e.g. QPainter::drawRect. Then I read somewhere that it is > better to create a Pixmap and then use it. I did get a little better > results with that but there still is this really anoying flickering. > Maybe someone could tell me what I'm doing wrong or whether there is a > better way to do this. > The code for the animation can be downloaded here: > http://www.aw-modell.at/mata/animationtest.tar.gz > > Thanks for any kind of help! > Matej > Pass this to the widgets wflags Qt::WNoAutoErase - indicates that the widget paints all its pixels. Updating, resizing, scrolling and focus changes should therefore not erase the widget. This allows smart-repainting to avoid flicker. You'll have to make sure you repaint all pixels, but if you do that correctly there should be no flicker. You'll either want to use a pixmap the same size of the widget, or make sure to paint each pixel only once( don't paint the background and then the square over it, instead paint the square, and use a qregion to paint the background everywhere except the square). Matt >> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<