How To Create QParallelAnimationGroup In Qt5 GUI

In this article we will learn How To Create QParallelAnimationGroup In Qt5 GUI, also we will learn how to use an animation group to manage the states of the animations contained in the group.

 

 

 

What is QParallelAnimationGroup In Qt5 ?

QParallelAnimationGroup–a container for animations–starts all its animations when it is started itself, i.e., runs all animations in parallel.

The animation group finishes when the longest lasting animation has finished.

You can treat QParallelAnimationGroup as any other QAbstractAnimation, e.g., pause, resume, or add it to other animation groups.

 

 

 

So first of all you need to create a New Project in Qt5 C++ Framework, after creating New Project you need to open your mainwindow.ui file and add three QPushButton in your design like this.

 

 

Qt5 QParallelAnimation Design
Qt5 QParallelAnimation Design

 

 

 

OK now you need to open your mainwindow.h file and add this

 

 

Also in the private section of your mainwindow.h we need to add these codes

 

 

 

After adding your mainwindow.h will look like this

 

 

 

 

So now open your mainwindow.cpp file and define the animation for each of the push buttons in the main window’s constructor.

 

 

 

After that, create an easing curve and apply the same curve to all three animations

 

 

 

Once you have applied the easing curve to all three animations, we will then create an
animation group and add all three animations to the group:

 

 

 

At the end call the start() function from the animation group we just created

 

 

 

Your complete code in mainwindow.cpp constructor will look like this

 

 

How it Works

Since we are using an animation group now, we no longer call the start() function from the
individual animation, but instead we will be calling the start() function from the animation
group we just created.
If you compile and run the example now, you will see all three buttons being played at the
same time. This is because we are using the parallel animation group.

You can replace it with a sequential animation group and run the example again

 

This time, only a single button will play its animation at a time, while the other buttons will
wait patiently for their turn to come.
The priority is set based on which animation is added to the animation group first. You can
change the animation sequence by simply rearranging the sequence of an animation being
added to the group. For example, if we want button 3 to start the animation first, followed
by button 2, and then button 1, the code will look like this:

 

 

Also check Qt5 C++ GUI Development Articles in the below links

1: Qt5 C++ Introduction And Installation

2: Qt5 C++ First Console Application 

3: Qt5 C++ First GUI Application 

4: Qt5 C++ Signal And Slots Introduction

5: Qt5 C++ Layout Management 

6: Qt5 C++ Creating Qt Style Sheets

7: Qt5 C++ Creating QPushButton

8: How To Create QCheckBox in Qt5

9: Qt5 GUI How To Create QRadioButton

10: Qt5 GUI Development How To Create ComboBox

11: Qt5 C++ GUI Development Creating QListWidget

12: Qt5 C++ GUI Development Creating QMessageBox

13 : Qt5 C++ GUI Creating QMenu And QToolbar

14: Qt5 C++ GUI Development Creating QPrintDialog

15: Qt5 C++ GUI Development Creating QFontDialog

16: Qt5 C++ GUI Development Creating QColorDialog

17: How to Create QFileDialog in Qt5 C++

18: How to Create QProgressbar in Qt5 C++

19: How to Create QPropertyAnimation in Qt5

20: How To Control QPropertyAnimation in Qt5 

 

 

So now run the complete project and you will see that three buttons are in one animation group

How To Create QParallelAnimationGroup In Qt5 GUI
How To Create QParallelAnimationGroup In Qt5 GUI

 

 

 

You can watch the complete video for QParallelAnimationGroup and QSequentialAnimationGroup

 

 

 

 

Subscribe and Get Free Video Courses & Articles in your Email

 

Share via
Copy link
Powered by Social Snap
×