我想用QStateMachine创建一个无限循环,其中我还需要动画。带动画的QStateMachine事件循环
QColor leastTransparent, mostTransparent = color();
leastTransparent.setAlpha(250);
mostTransparent.setAlpha(150);
QState *s1 = new QState();
s1->assignProperty(this, "color", leastTransparent);
QState *s2 = new QState();
s2->assignProperty(this, "color", mostTransparent);
QSignalTransition *transition = s1->addTransition(this, SIGNAL(triggerSignal()),s2);
QSignalTransition *transition2 = s2->addTransition(s2, SIGNAL(entered),s1);
QPropertyAnimation* animation = new QPropertyAnimation(this, "color");
animation->setDuration(5000);
transition->addAnimation(animation);
QPropertyAnimation* animation2 = new QPropertyAnimation(this, "color");
animation2->setDuration(10000);
transition2->addAnimation(animation2);
m_stateMachineAnimation->addState(s1);
m_stateMachineAnimation->addState(s2);
m_stateMachineAnimation->setInitialState(s1);
m_stateMachineAnimation->setGlobalRestorePolicy(QStateMachine::RestoreProperties);
m_stateMachineAnimation->start();
我期望的是在“triggerSignal”之后的第一个5秒钟,颜色会变得更加不透明。国家将是“s2”。并且比“s2”的输入信号被触发,并且它将在10秒内变得越来越透明。
但是,相反,我正在s2触发器立即没有等待5秒后立即“触发信号”,并立即s1再次触发不等待10秒。
为什么我的持续时间不被QStateMachine考虑在内。我如何用QStateMachine实现这样的动画
你可以发布[S.S.C.C.E.](http://www.sscce.org/)吗? –