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 Buttonstemplate. - Drag and drop a
Labelwidget and onePush Buttonwidget onto the form. - Set the
textproperty of thePush Buttonwidget toMove With Curve. - Assuming you have a ball image on your computer with the filenameÂ
coloredball.jpg, you can assign this ball image to theLabelwidget by using itspixmapproperty. - In the
pixmap...