After a little research, it seems that QVariantAnimationfrom which it is inherited QPropertyAnimationdoes not support QStringas a property of the animation. A list of all supported properties is here (Int, UInt, Double, Float, QLine, QLineF, QPoint, QPointF, QSize, QSizeF, QRect, QRectF, QColor)
, , .
- Q_PROPERTY(QColor color READ color WRITE setColor)
setColor .
QLabel :
class AnimatedLabel : public QLabel
{
Q_OBJECT
Q_PROPERTY(QColor color READ color WRITE setColor)
public:
AnimatedLabel(QWidget *parent = 0)
{
}
void setColor (QColor color){
setStyleSheet(QString("background-color: rgb(%1, %2, %3);").arg(color.red()).arg(color.green()).arg(color.blue()));
}
QColor color(){
return Qt::black; // getter is not really needed for now
}
};
:
QPropertyAnimation *animation = new QPropertyAnimation(ui->label, "color");
animation->setDuration(2000);
animation->setStartValue(QColor(0, 0, 0));
animation->setEndValue(QColor(240, 240, 240));
animation->start();
ui- > label - AnimatedLabel ( QLabel AnimatedLabel .