[Qt-interest] widget update problem
Andre Somers
andre at familiesomers.nl
Fri Oct 2 12:15:27 CEST 2009
Alexander Carôt wrote:
> Hi all,
>
> I have a question related to a simple animation of a widget: After the click of a button I want to make another widget visible and moving it from left to right. I created a slot, which is triggered by the button click:
>
> void JamDesk::jamButtonClicked(){
> ui.LMixer->setVisible(true);
>
> for (int i=1;i<5;i++){
> ui.LMixer->setGeometry(i, ui.LMixer->y(),
> ui.LMixer->width(),ui.LMixer->height() );
> this->update();
> sleep(1000);
> }
> }
>
> So, it should be visible and then move from x-coordinate 1 to 4 and after each move it should stop moving for one second. This, however, doesn't work: What happens instead is that I don't see anything for 5 seconds and then it shows up at the final and correct spot. Update and repaint don't work althoug the widget has updates enabled.
>
> Can anyone tell where my problem is ?
>
>
>
You don't give Qt the chance to do anything for 5 seconds. Don't use
sleep(). If you want something to happen with an interval, use a QTimer
instead.
What I would do, is use QTimeLine. It is made for cases like this.
Create a slot to adjust the position of your object according to a value
between 0.0 and 1.0, hook it up to the QTimeLine, and then call start()
on the time line. This way, you don't block the event queue (blocking
the drawing), you don't block the rest of your application just for a
simple animation, you get real framerates, and you get some nice curve
shapes to choose from for free.
André
More information about the Qt-interest-old
mailing list