Cpper
C/C++高级工程师 Android高级软件工程师 IT集成工程师 音频工程师 熟悉c,c++,java,c#,py,js,asp等多种语言 程序猿
效果不太明显
class StateMachine : public QWidget
{
    Q_OBJECT
public:
    StateMachine(QWidget 
*parent = 0, Qt::WFlags flags = 0);
    
~StateMachine();
private:
    
void createWidget();
private:
    QStateMachine
* machine;
    QState
*        state1;
    QState
*        state2;

    QLayout
*       layout;

    QLineEdit
*     edit1;
    QPushButton
*   button1;
    QLineEdit
*     edit2;
    QPushButton
*   button2;
};

StateMachine::StateMachine(QWidget *parent, Qt::WFlags flags):
QWidget(parent,flags)
{
    machine 
= new QStateMachine;
    state1 
= new QState(machine);
    state2 
= new QState(machine);
    createWidget();
}

StateMachine::
~StateMachine()
{
}

void StateMachine::createWidget()
{
    layout 
= new QHBoxLayout(this);
    edit1 
= new QLineEdit("QLineEdit1");
    button1 
= new QPushButton("Click1");
    
    edit2 
= new QLineEdit("QLineEdit2");
    button2 
= new QPushButton("Click2");
    edit2
->setVisible(false);
    button2
->setVisible(false);

    layout
->addWidget(edit1);
    layout
->addWidget(button1);
    layout
->addWidget(edit2);
    layout
->addWidget(button2);
     
    state1
->assignProperty(edit2,"visible",false);
    state1
->assignProperty(button2,"visible",false);
    state1
->assignProperty(edit1,"visible",true);
    state1
->assignProperty(button1,"visible",true);
    machine
->setInitialState(state1);

    state2
->assignProperty(edit1,"visible",false);
    state2
->assignProperty(button1,"visible",false);
    state2
->assignProperty(edit2,"visible",true);
    state2
->assignProperty(button2,"visible",true);

    QPropertyAnimation
* ani = new QPropertyAnimation();
    ani
->setDuration(2000);
    ani
->setEasingCurve(QEasingCurve::InOutExpo);   

    QSignalTransition 
*transition1=state1->addTransition(button1,SIGNAL(clicked()),state2);    
    transition1->addAnimation(ani);
    QSignalTransition 
*transition2=state2->addTransition(button2,SIGNAL(clicked()),state1);
    transition2
->addAnimation(ani);
    machine
->start();  
}
posted on 2012-07-30 23:09 ccsdu2009 阅读(695) 评论(0)  编辑 收藏 引用 所属分类: QT编程

只有注册用户登录后才能发表评论。
【推荐】超50万行VC++源码: 大型组态工控、电力仿真CAD与GIS源码库
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理