Animation is based on keyframes. In Qt Design Studio, keyframes determine the value of the property of a component at a certain time. Animating properties enables their values to move through intermediate values instead of immediately changing to the target value.
For example, you can set the y position property of a rectangle to 0 at the start of your animation and to 100 at the end of the animation. When the animation is run, the rectangle moves from position 0 to 100 on the y axis. In the middle of the animation, the y property has the value of 50 since keyframes are interpolated linearly by default.
Sometimes you don't want linear movement but would rather like the rectangle to move faster at the beginning and slower at the end of the animation. To achieve this effect, you could insert a lot of keyframes between the start frame and the end frame. To avoid this effort, you can use the Easing Curve Editor to specify easing curves for nonlinear interpolation between keyframes. The easing curves can make components appear to pick up speed, slow down, or bounce back at the end of the animation.
While easing curves work well for most simple UI animations, more complex 3D animations require several keyframes so it becomes necessary to visualize the value and the interpolation of a keyframe simultaneously. The Curve Editor visualizes the whole animation of a property at once and shows the effective values of a keyframe together with the interpolation between keyframes. It can also show animations of different properties simultaneously so that you can see the animation for the x position side-by-side with the animation of the y position.
You can declare various UI states as states, which are specified as changes from a base state and can be a useful way of organizing your UI logic. You can bind animations to states to run an animation when a state is applied.
Each component in a scene or a project can have its own timeline and its own set of states. We recommend that you place your timelines inside the components and precompose them. Each component's timeline runs independently of the rest of the scene, allowing for time-independent animations. Additionally, separate states allow common functionality to be factored out and reused across the scene. Do note, however, that adding states and timelines to your components will increase the file size and runtime memory requirements of your UI.
The following video shows how to animate component properties using the timeline and keyframe based editor in the Timeline view:
You specify settings for the timeline and for running the animation in the Timeline Settings dialog. The Animation radio button is selected for a timeline animation and the Expression binding radio button for a property animation.
To create a timeline to animate a UI component:
- In the Timeline view, select the (Add Timeline) button to specify settings for the timeline and running the animation in the Timeline Settings dialog.
- In the Timeline ID field, enter an ID that describes the animated component.
- In the Start frame field, set the first frame of the timeline. Negative values are allowed.
- In the End frame field, set the last frame of the timeline.
- In the Animation ID field, enter an ID for the animation.
- Select the Running in Base State check box to run the animation when the base state is applied. Deselect the check box if you want to run the animation when some other state is applied. For more information, see Binding Animations to States.
- In the Start frame field, set the first frame of the animation.
- In the End frame field, set the last frame of the animation.
- In the Duration field, set the length of the animation from the start frame to the end frame. If you set a shorter duration than the number of frames, frames are left out from the end of the animation when viewing it.
- Select the Continuous check box to loop the animation indefinitely.
- In the Loops field, select the number of times to run the animation as a loop. The default number of loops is one, which means that you must restart the animation to see it again
- Select the Ping pong check box to play the animation backwards back to the beginning when it reaches the end.
- In the Finished field, select the state to apply when the animation finishes.
- Select Close to close the dialog and save the settings.
To create additional timelines, select the (Add Timeline) button next to the Timeline Settings tab.
To specify settings for running timeline animations, select the (Add Animation) button next to the Animation Settings tab. For example, you could create settings for running a part of the timeline animation between specified frames or for running the animation backwards from the last frame to the first.
The table at the bottom of the Timeline Settings dialog lists the available states. Double-click the values in the Timeline and Animation column to bind the states to animations. In the Fixed Frame column, you can bind the states that don't have animations to fixed frames.
To animate components in the Timeline view, move to a frame on the timeline and specify changes in the values of a property. Qt Design Studio automatically adds keyframes between two keyframes and sets their values evenly to create an appearance of movement or transformation.
You can insert keyframes for all the properties of all the components that you want to animate first, and then record the changes in their values by selecting the (Per Property Recording) button for one property at a time. For example, you can hide and show components by turning their visibility off and on or by setting their opacity to 0 or 1.
You can also select the Auto Key (K) button (or press K) to record changes in property values, but you need to be more careful about which property values you are changing to avoid surprises.
To record the changes of property values:
- In the Navigator view, select the component to animate.
- In the Properties view, select Settings > Insert Keyframe for the property that you want to animate.
- In the Timeline view, select the Per Property Recording button to start recording property changes.
- Check that the playhead is in frame 0 and enter the value of the property in the field next to the property name on the timeline. Press Enter to save the value.
- Move the playhead to another frame on the timeline and specify the value at that frame. For more information, see Navigating in Timeline.
- When you have specified as many values as you need, select Per Property Recording again to stop recording.
To remove all the changes you recorded for a property, right-click the property name on the timeline and select Remove Property.
To add keyframes to the keyframe track of a component at the current position of the playhead, select Add Keyframes at Current Frame.
To fine-tune the value of a keyframe, double-click a keyframe marker or select Edit Keyframe in the context menu.
The Edit Keyframe dialog displays the name of the property you are animating and its current value at the frame specified in the Frame field. You can change both the keyframe and its value.
You can copy the keyframes from the keyframe track for a component and paste them to the keyframe track of another component. To copy all keyframes from one track to another one, first right-click the component ID and select Copy All Keyframes in the context menu. Then right-click the other component ID, and select Paste Keyframes in the context menu.
To delete the selected keyframe, select Delete Keyframe in the context menu.
To delete all keyframes from the selected component, select Delete All Keyframes in the context menu.
You can view the animation on the canvas by moving the playhead along the timeline.
To preview the animation, select the Play (Space) button or press Space. To preview the whole UI, select the (Show Live Preview) button on the canvas toolbar or press Alt+P.
To animate components that rotate around a central point, you can use the Item component as a parent for the rotating component. Then create a timeline for the Item, and set the rotation property for the start and end keyframes.
You can use the Qt Quick Studio Components to animate the following shapes:
Available under certain Qt licenses.
Find out more.