Qt状态机_C/C++_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > C/C++ > Qt状态机

Qt状态机

 2013/12/3 15:26:11  缥缈孤鸿  程序员俱乐部  我要评论(0)
  • 摘要:#include<QApplication>#include<QStateMachine>#include<QPushButton>#include<QSignalTransition>#include<QPropertyAnimation>intmain(intargc,char**argv){QApplicationapp(argc,argv);QWidget*w=newQWidget;w->resize(240,320)
  • 标签:

class="c++" name="code">
#include <QApplication>
#include <QStateMachine>
#include <QPushButton>
#include <QSignalTransition>
#include <QPropertyAnimation>

int main(int argc,char **argv)
{
    QApplication app(argc,argv);
    QWidget *w=new QWidget;
    w->resize(240,320);
    QPushButton *button = new QPushButton("hicjiajia",w);
    QStateMachine *machine = new QStateMachine;     //新建状态机
    QState *state1 = new QState(machine);     //状态1
    state1->assignProperty(button,"geometry",QRect(0,0,80,30));    //绑定button的geomertry属性
    machine->setInitialState(state1);     //state1设为初始化状态
    QState *state2 = new QState(machine);
    state2->assignProperty(button,"geometry",QRect(w->width()-30,w->height()-80,30,80));
    QFont font = QFont("Airl", 12);
    state2->assignProperty(button,"font",font);     //状态2字体


    QPropertyAnimation *ani=new QPropertyAnimation(button,"geometry");
    ani->setDuration(2000);
    ani->setEasingCurve(QEasingCurve::OutBounce);   //动画效果—弹跳

    QSignalTransition *transition1=state1->addTransition(button,SIGNAL(clicked()),state2);      //动画触发信号
    transition1->addAnimation(ani);
    QSignalTransition *transition2=state2->addTransition(button,SIGNAL(clicked()),state1);
    transition2->addAnimation(ani);
    machine->start();     //开启状态机

    w->show();
    return app.exec();
}
上一篇: Java 下一篇: Cheatsheet: 2013 11.12 ~ 11.30
  • 相关文章
发表评论
用户名: 匿名