Making a ball animate as per the specified curve
A curve with the desired shape and size is created and a ball is set to move along the shape of the curve on the click of a push button. In this recipe, you will understand how to implement a guided animation.
How to do it...
The setKeyValueAt
method of the QPropertyAnimation
class determines the direction of an animation. For guided animation, you invoke the setKeyValueAt
method in a loop. The coordinates of the curve are passed to the setKeyValueAt
method in the loop to make the ball animate along the curve. Here are the steps to make an object animate as desired:
- 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 With Curve
. - Assuming you have a ball image on your computer with the filename
coloredball.jpg
, you can assign this ball image to theLabel
widget by using itspixmap
property. - In the
pixmap...