How to Control QPropertyAnimation in Qt5 with QEasingCurve

How to Control QPropertyAnimation in Qt5 with QEasingCurve – In this example, we will learn how to make our animation more interesting by utilizing easing
curves. We will still use the previous source code, which uses the QPropertyAnimation to animate a push button.

 

So now open your mainwwindow.cpp and before starting animation add these codes

 

 

Let me describe this code, first of all we have defined an easing curve and add that to property animation before calling the start() function.

also we have a setLoopCount() function to set how many loops you want it to repeat for.

and at the end we have called the  setAmplitude(), setOvershoot(), and setPeriod() before applying the easing
curve to the animation.

 

After adding your complete code will look like this in mainwindow.cpp

 

 

 

How it Works

In order to let an easing curve control the animation, all you need to do is to define an
easing curve and add it to the property animation before calling the start() function. You
can also try several other types of easing curve and see which one suits you best. Here is
an example:

 

 

 

If you want the animation to loop after it has finished playing, you can call the
setLoopCount() function to set how many loops you want it to repeat for, or set the value
to -1 for an infinite loop.

 

 

 

There are several parameters that you can set to refine the easing curve before applying it
to the property animation. These parameters include amplitude, overshoot, and period:

  • Amplitude: The higher the amplitude, the higher the bounce or elastic spring effect that
    will be applied to the animation.
  • Overshoot: Some curve functions will produce an overshoot (exceeding its final value)
    curve due to damping effect. By adjusting the overshoot value, we are able to increase
    or decrease this effect.
  • Period: Setting a small period value will give a high frequency to the curve. A large
    period will give it a small frequency.

These parameters, however, are not applicable to all curve types. Please refer to the Qt
documentation to see which parameter is applicable to which curve type.

 

 

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

 

 

 

OK at the end run the project and this will be the result

How to Control QPropertyAnimation in Qt5 with QEasingCurve
How to Control QPropertyAnimation in Qt5 with QEasingCurve

 

 

 

Also you can watch the complete video for this article 

 

 

 

 

 

Subscribe and Get Free Video Courses & Articles in your Email

 

Codeloop
Share via
Copy link
Powered by Social Snap
×