那么,我正在开发一个Qt应用程序,我想使用Qt状态框架做一些动画.
第一:
如何通过使用状态转换来将包含在水平布局中的一组按钮动画化为另一个垂直布局?
第二:
处于状态时如何显示窗口小部件?例如菜单:当用户单击菜单中的按钮时,将显示窗口小部件(以前已使用窗口小部件> hide()隐藏)… …
这是一个代码示例:
BoxInsert = new BoxInsert(this); BoxInsert->hide (); btn1 = new QPushButton("Introducir",this); btn2 = new QPushButton("Informe",this); btn3 = new QPushButton("Salir",this); QStateMachine *machine = new QStateMachine(this); QState *st1 = new QState(machine); st1->setObjectName ("menuMode"); st1->assignProperty (btn1,"pos",QPointF(center - btn1->width () / 2,20)); st1->assignProperty (btn2,40)); st1->assignProperty (btn3,60)); st1->assignProperty (BoxInsert,"visible",QVariant(false)); QState *st2 = new QState(machine); st2->setObjectName ("barMode"); st2->assignProperty (btn1,QPointF(40,0)); st2->assignProperty (btn2,0)); st2->assignProperty (btn3,0)); st1->assignProperty (BoxInsert,QVariant(true)); machine->setInitialState (st1); QAbstractTransition *t1 = st1->addTransition (btn1,SIGNAL(clicked()),st2); //QSequentialAnimationGroup *sq1 = new QSequentialAnimationGroup; //sq1->addPause (250); t1->addAnimation (new QPropertyAnimation(btn1,"pos")); t1->addAnimation (new QPropertyAnimation(btn2,"pos")); t1->addAnimation (new QPropertyAnimation(btn3,"pos")); t1->addAnimation (new QPropertyAnimation(BoxInsert,"visible")); machine->start ();
解决方法
这样的东西就像当你启动机器时会改变一个按钮的颜色,这个按钮的颜色可能表明这是被点击的,然后执行与你的信号链接的东西,所以链接的插槽将被执行.
s0->addTransition(s1); s1->assignProperty(ui->pushButton,"styleSheet","background-color:rgb(255,0);"); s1->addTransition(s2); s2->addTransition(ui->pushButton,s0); QStateMachine m; m.addState(s0); m.addState(s1); m.addState(s2); m.setInitialState(s0);
要使可见窗口小部件添加如下状态转换:
s1->assignProperty(MyWid,true);
并在状态s1的s0中添加转换.