PDA

View Full Version : Background color animation



cszawisza
19th November 2015, 21:25
Hi!

I want to animate changing of background color in a window using QPropertyAnimation


QPalette start;
start.setColor(QPalette::Window, QColor(1,255,0));

QPalette stop;
stop.setColor(QPalette::Window, QColor(255,255,255));
animation = new QPropertyAnimation(this, "palette");
animation->setDuration(100);
animation->setStartValue(start);
animation->setEndValue(stop);
animation->setLoopCount(-1);
animation->start();


But after "starting" the animation nothing happen...
Is there a way to change the background color of window by simple calling some property? (Without overloading or creating own properties by Q_PROPERTY)

anda_skoa
19th November 2015, 21:43
Did you call setAutoFillBackground(true) on the widget?

Cheers,
_

cszawisza
20th November 2015, 09:02
Yes, I add that line, without any good result



ui->setupUi(this);
this->setAutoFillBackground(true);
QPalette start, stop;

start.setColor(QPalette::Window, QColor(0,255,0));
stop.setColor(QPalette::Window, QColor(255,0,0));
animation = new QPropertyAnimation(this, "palette");
animation->setDuration(100);
animation->setStartValue(start);
animation->setEndValue(stop);
animation->setLoopCount(-1);

connect(ui->pushButton, &QPushButton::clicked,
[&](){
qDebug() << "Animation button clicked";
animation->start();
});



This is the whole "app" that I was testing animations on... (standard new mainwindow project from qtcreator with pushbutton)
some further suggestions?

cszawisza
25th November 2015, 11:48
One thing that worked was to add own "color" property to widget.

anda_skoa
25th November 2015, 13:37
The problem could be that QPropertyAnimation does not know how to interpolate between QPalette values since a QPalette is quite a complex object with lots of sub values.

Cheers,
_