【发布时间】:2014-10-20 07:25:49
【问题描述】:
我想为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();
但它不起作用,没有任何反应,刷子的颜色和以前一样。我应该怎么做才能解决它?
【问题讨论】:
-
最后有一个。
-
当我发表评论时没有
?,编辑修复了它。看起来更好。
标签: c++ qt qproperty qpropertyanimation