Using easing curves to control property animation
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 property animation to animate a push button.
How to do it…
- Define an easing curve and add it to the property animation before calling the
start()function:QPropertyAnimation *animation = new QPropertyAnimation(ui->pushButton, "geometry"); animation->setDuration(3000); animation->setStartValue(ui->pushButton->geometry()); animation->setEndValue(QRect(200, 200, 100, 50)); QEasingCurve curve; curve.setType(QEasingCurve::OutBounce); animation->setEasingCurve(curve); animation->start();
- Call the
setLoopCount()function to set how many loops you want it to repeat for:QPropertyAnimation *animation = new QPropertyAnimation(ui->pushButton, "geometry"); animation->setDuration(3000); animation->setStartValue(ui->pushButton->geometry...
You have been reading a chapter from
Qt5 C++ GUI Programming Cookbook
Published in:
Jul 2016
Publisher:
Packt
ISBN-13:
9781783280278
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime