I would like to animate the size of the QPushButton icon, because when i try to animate whole QPushButton object size, icon is not resizing at all. It seems theres no property "setScaledContents" on QPushButton icon. I tried to use this code for icon in my custom QPushButton method (on hover):
QIcon *icon = new QIcon(this->icon());
QPropertyAnimation *animation = new QPropertyAnimation((QObject*)icon, "size");
animation->setDuration(1000);
QSize test = this->size();
animation->setStartValue(test);
animation->setEndValue(QSize(test.width()+100,test.height()+100));
animation->start();
But i receive an error "segmentation failed" on this code. Is there any other way i can animate my QPushButton icon?
QIcon
doesn't inherit fromQObject
, so this type cast:(QObject*)icon
is dangerous and wrong. – ChrisQPropertyAnimation *animation = new QPropertyAnimation(this, "iconSize"); animation->setDuration(500); // QSize test = this->size(); animation->setStartValue(QSize(1024,1024)); animation->setEndValue(QSize(512,512)); animation->start();
but it doesn't work – SirLanceloaaat