Create a dissolvence animation in Qt Creator
-
Hey guys,
I am building a simple project where I wanna put modern buttons.
I tried the flat style on the properties but I cannot use stylesheets then.
So I madeui->pushbutton->setStyleSheet("QPushButton {border: 1px;}");
Then I made QPushButton:hover where I change the background color.
My question is: How do I create a dissolvence animation from a color to another in Qt Creator?
Like when it is clicked, the color get darker. How do I make this?
Thanks -
@HenkCoder said in Create a dissolvence animation in Qt Creator:
My question is: How do I create a dissolvence animation from a color to another in Qt Creator?
You can use
QPropertyAnimation
for this.Change the
QGraphicsColorizeEffect
viaQPropertyAnimation
from your starting color to your final color. -
Create a
QGraphicsColorizeEffect
and assign it to your button.QGraphicsColorizeEffect *colorEffect = new QGraphicsColorizeEffect(); ui->pushButton->setGraphicsEffect(colorEffect);
Then create a
QPropertyAnimation
to animate (change value over time) one of the effect's properties
Either the color or the color strenght.QPropertyAnimation *ani = new QPropertyAnimation(colorEffect, "color"); // put property name here ani->setStartValue( #YOUR_COLOR# ); // Start value, e.g. QColor(255, 255, 0) ani->setEndValue( #YOUR_COLOR# ); // End value // Then set a duration in msecs ani->setDuration(750); // and start whenever you want ani->start();
Optional you can add an ease function (default is linear from start to end value)
ani->setEasingCurve( QEasingCurve::InCubic );
Note: Not tested, but should work :)
(This is the way I would do it)