【发布时间】:2014-08-14 12:03:18
【问题描述】:
我有一个派生自 QGraphicsPolygonItem 的类。里面有一个负责动画的函数。函数如下:
void DrawBase::makeAnimation(){
/* creating 2 states */
QState* st1 = new QState();
QState* st2 = new QState();
st1->addTransition(this, SIGNAL(clicked()), st2);
st2->addTransition(this, SIGNAL(clicked()), st1);
/* adding states to state machine */
_stateMachine.addState(st1);
_stateMachine.addState(st2);
_stateMachine.setInitialState(st1);
QObject::connect(st1, SIGNAL(entered()), this, SLOT(animate1()));
QObject::connect(st2, SIGNAL(entered()), this, SLOT(animate2()));
/* starting machine */
_stateMachine.start();
}
连接的插槽 animate1() 和 animate2() 看起来像:
void DrawBase::animate1()
{
qDebug() << "Animation 1";
animation = new QPropertyAnimation(this, "polygon");
animation->setDuration(1000);
animation->setStartValue(this->polygon());
QTransform trans;
trans=trans.scale(0.5,0.5);
QPolygonF newPoly=trans.map(this->polygon());
animation->setEndValue(newPoly);
animation->setEasingCurve(QEasingCurve::OutBounce);
animation->start();
}
QPropertyAnimation 没有看到 Polygon 属性,所以我在标题中定义了该属性,如下所示:
Q_PROPERTY (QPolygonF 多边形 READ polygonNew WRITE setPolygonNew) PolygonNew 和 setPolygonNew 调用 QGraphicsPolygonItem 类的 polygon() 和 setPolygon()。
结果动画已启动但无法正常工作,我不确定它是否适用于多边形项目。在动画开始的时候,polygonNew 被调用了 3 次,setPolygonNew 根本没有被调用。有人对我如何使它起作用有想法吗?
【问题讨论】:
标签: qt qt4 qt5 qgraphicsscene