当前位置:首页 > 开发 > 编程语言 > 编程 > 正文

Qt状态机实例

发表于: 2013-12-03   作者:缥缈孤鸿   来源:转载   浏览:
摘要: #include <QApplication> #include <QStateMachine> #include <QPushButton> #include <QSignalTransition> #include <QPropertyAnimation> int main(int argc,char **argv)
#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();
}

Qt状态机实例

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

推荐文章
编辑推荐
版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号