Cpper
C/C++高级工程师 Android高级软件工程师 IT集成工程师 音频工程师 熟悉c,c++,java,c#,py,js,asp等多种语言 程序猿
#include <QApplication> 
#include 
<QStateMachine> 
#include 
<QPushButton>
#include 
<QTextEdit>
#include 
<QHBoxLayout>
#include 
<QVBoxLayout>
#include 
<QSpacerItem>
#include 
<QSignalTransition> 
#include 
<QPropertyAnimation> 

int main(int argc,char **argv)
{  
    QApplication app(argc,argv);  

    QWidget
* panel = new QWidget;  
    panel
->resize(320,360);  

    QVBoxLayout
* layout = new QVBoxLayout();
    panel
->setLayout(layout);
                   
    QPushButton
* button = new QPushButton("Click");
    QSpacerItem
* spacer = new QSpacerItem(40,20,QSizePolicy::Expanding,QSizePolicy::Minimum);
    QHBoxLayout
* hlayout = new QHBoxLayout();
    layout
->addLayout(hlayout);
    hlayout
->addItem(spacer);
    hlayout
->addWidget(button);

    QTextEdit
* edit1 = new QTextEdit();
    edit1
->setGeometry(QRect(10,50,300,300));
    QTextEdit
* edit2 = new QTextEdit();
    edit2
->setGeometry(QRect(10,300,300,0));
    layout
->addWidget(edit1);
    layout
->addWidget(edit2);

    QStateMachine
* machine = new QStateMachine;
    
    QState
* state1 = new QState(machine);      
    state1
->assignProperty(edit1,"geometry",QRect(10,50,300,300));
    state1
->assignProperty(edit2,"geometry",QRect(10,300,300,0));
 
    QState
* state2 = new QState(machine);  
    state2
->assignProperty(edit1,"geometry",QRect(10,50,300,0)); 
    state2
->assignProperty(edit2,"geometry",QRect(10,50,300,300));
                
    machine
->setInitialState(state1);  

    QPropertyAnimation
* ani1 = new QPropertyAnimation(edit1,"geometry"); 
    ani1
->setDuration(2000);    
    ani1
->setEasingCurve(QEasingCurve::OutBounce);    
    
    QPropertyAnimation
* ani2 = new QPropertyAnimation(edit2,"geometry"); 
    ani2
->setDuration(2000);    
    ani2
->setEasingCurve(QEasingCurve::InOutExpo);

    QSignalTransition
* transition1 = state1->addTransition(button,SIGNAL(clicked()),state2);
    QSignalTransition
* transition2 = state2->addTransition(button,SIGNAL(clicked()),state1); 

    transition1
->addAnimation(ani1);   
    transition1
->addAnimation(ani2); 
    transition2
->addAnimation(ani1); 
    transition2
->addAnimation(ani2); 
    
    machine
->start();   
    panel
->show();  
    
    
return app.exec();  
}
posted on 2013-01-02 17:35 ccsdu2009 阅读(2140) 评论(1)  编辑 收藏 引用 所属分类: QT编程
Comments

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理