我想要动画颜色QBrush
。更多详情请看下面的代码
这是我的 .h 文件
class Cell : public QObject, public QGraphicsRectItem
{
Q_OBJECT
Q_PROPERTY(QBrush brush READ brush WRITE set_Brush)
public:
QBrush _brush() const;
void set_Brush(const QBrush&);
Cell(QGraphicsItem *parent = 0); //конструктор
}
这是我的 .cpp 文件
Cell::Cell(QGraphicsItem *parent)
: QObject(), QGraphicsRectItem(parent)
{
this->setRect(0, 0, Scale, Scale);
}
QBrush Cell::_brush() const
{
return this->brush();
}
void Cell::set_Brush(const QBrush & brush)
{
this->setBrush(brush);
}
这就是动画:
QPropertyAnimation* animation = new QPropertyAnimation(selectedCell, "brush");
animation->setDuration(10000);
animation->setStartValue(QBrush(QColor(255,0,0)));
animation->setEndValue(QBrush(QColor(0,255,0)));
animation->start();
但它不起作用,什么也没有发生,画笔的颜色和以前一样。我应该做什么来修复它?