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.
I am creating an application in which i am using a loop within a
Share
Don’t use
sleep/msleepinpaintEvent(). 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
QTimerto receive signals four times every 500ms. In the processing slot, update a member variable to indicate how many rectangles to draw and callupdate()on the widget. Then in the widget’spaintEvent(), check the member variable, draw your rectangles and return as soon as possible.(For more complex animation needs, have a look at
QTimeLine.)