Making a ball move down on the click of a button
In this recipe, you will understand how a basic animation is applied on an object. This recipe will consist of a push button and a ball, and when the push button is pressed, the ball will start animating towards the ground.
How to do it...
To make this recipe, we will be making use of the QPropertyAnimation
class. The setStartValue()
and setEndValue()
methods of the QPropertyAnimation
class will be used to define the coordinates where the animation needs to start and end, respectively. The setDuration()
method will be invoked to specify the delay in milliseconds between every animation move. The following is the step-by-step procedure to apply an animation:
- Create a new application based on the
Dialog without Buttons
template. - Drag and drop a
Label
widget and onePush Button
widget onto the form. - Set the
text
property of thePush Button
widget toMove Down
. We assume that you have a ball image on your computer with the filenamecoloredball.jpg
...