这是以前做一个医疗系统的一部分程序,只是这个项目不了了之了。
如下图所示:
/** * @brief machine 状态机 */ QStateMachine *machine = new QStateMachine; /** * @brief machine1 */ QStateMachine *machine1 = new QStateMachine; QState *s1 = new QState(machine); s1->assignProperty(ui->label,"geometry",QRect(80,60,50,120)); QState *s2 = new QState(machine); s2->assignProperty(ui->label,"geometry",QRect(10,10,35,85)); machine->setInitialState(s2); QState *s3 = new QState(machine1); s3->assignProperty(ui->label_2,"geometry",QRect(10,10,35,85)); QState *s4 = new QState(machine1); s4->assignProperty(ui->label_2,"geometry",QRect(80,60,50,120)); machine1->setInitialState(s4); QPropertyAnimation *ani = new QPropertyAnimation(ui->label,"geometry"); ani->setDuration(1000); ani->setEasingCurve(QEasingCurve::OutCurve); QPropertyAnimation *ani1 = new QPropertyAnimation(ui->label_2,"geometry"); ani1->setDuration(1000); ani1->setEasingCurve(QEasingCurve::InCurve); QEventTransition *s1tos2 = new QEventTransition(ui->label_2, QEvent::MouseButtonPress); s1tos2->setTargetState(s2); s1->addTransition(s1tos2); s1tos2->addAnimation(ani); QEventTransition *s3tos4 = new QEventTransition(ui->label_2, QEvent::MouseButtonPress); s3tos4->setTargetState(s4); s3->addTransition(s3tos4); s3tos4->addAnimation(ani1); QEventTransition *s2tos1 = new QEventTransition(ui->label, QEvent::MouseButtonPress); s2tos1->setTargetState(s1); s2->addTransition(s2tos1); s2tos1->addAnimation(ani); QEventTransition *s4tos3 = new QEventTransition(ui->label, QEvent::MouseButtonPress); s4tos3->setTargetState(s3); s4->addTransition(s4tos3); s4tos3->addAnimation(ani1);一个小人一个状态机,一个状态机有两个状态,为改变位置和大小,触发转换的是点击放置图片的label,在状态转换时,我们是使用了动画,才得出了两个小人现在的这个效果