Unsolved 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. -
@Pl45m4
Can you explain what do I have to do please?
I don't really understand well the Documentation -
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) -
@Pl45m4
Ok thank you, I'm gonna try It later -
@Pl45m4
And how do I make it return like before? With the same code? -
@Pl45m4
Hey, the code doesn't work, I tried it and it doesn't change anything.
But when I add the QPushButton:hover in the StyleSheet it kinda works, but the EndValue gets lighter and not darker -
@HenkCoder Is the last thing there because I'm mixing StyleSheets and Qt styling?