tags:

views:

28

answers:

2

hi everyone,I am creating an application in which i am using a loop within a paintevent to draw four rectangles.and i want that each rectangle must be drawn after 500ms.for that i am applying msleep().but by using this whenever i run the application,it hangs up for 2000ms and then draws all the rectangles at the same time.can anyone tell me a solution for this problem so that each rectangle is drawn after a delay. Thank you.

A: 

i do not know qt, but i think the answer lies with the use of a timer.

mangokun
+4  A: 

Don't use sleep/msleep in paintEvent(). You want to process your events quickly and not spend 2 seconds in the function call. The thread cannot process any other events while it's running your event processing code.

In a simple case like this you can use a QTimer to receive signals four times every 500ms. In the processing slot, update a member variable to indicate how many rectangles to draw and call update() on the widget. Then in the widget's paintEvent(), check the member variable, draw your rectangles and return as soon as possible.

(For more complex animation needs, have a look at QTimeLine.)

laalto
can you please provide me a snapshot that how to do this for my code?
neha
as expect drawing the four rectangles paint event is doing other things also,and i need the delay only while the rectangles are drawn.so i can not call update many times.so i dont know how to use QTimer.
neha