Cpper
C/C++高级工程师 Android高级软件工程师 IT集成工程师 音频工程师 熟悉c,c++,java,c#,py,js,asp等多种语言 程序猿
#ifndef QTEST_H
#define QTEST_H
#include 
<QWidget>
#include 
<QState>
#include 
<QStateMachine>
#include 
"ui_test.h"

class QTest : public QWidget
{
    Q_OBJECT
public:
    QTest(QWidget 
*parent = 0, Qt::WFlags flags = 0);
    
~QTest();
private:
    UI ui;
    QStateMachine
* machine;
    QState
* state1;
    QState
* state2;
};

#endif
#include <QPropertyAnimation>
#include 
<QSignalTransition>
#include 
"qtest.h"
#include 
<iostream>

QTest::QTest(QWidget 
*parent, Qt::WFlags flags):QWidget(parent, flags)
{   
    machine 
= new QStateMachine(this);
    state1 
= new QState(machine); 
    state2 
= new QState(machine); 
    
    ui.setupUi(
this);

    QSize size(
300,280);
 
    
//state1->assignProperty(ui.groupBox,"size",size);
    state1->assignProperty(this,"size",QSize(313,224));
    
//state2->assignProperty(ui.groupBox,"size",QSize(size.width(),0));
    state2->assignProperty(this,"size",QSize(313,40));
    
//state2->assignProperty(ui.);
    
    
/*QPropertyAnimation* ani1 = new QPropertyAnimation(ui.groupBox,"size");  
    ani1->setDuration(800);    
    ani1->setEasingCurve(QEasingCurve::Linear); 
*/ 

    QPropertyAnimation
* ani2 = new QPropertyAnimation(this,"size");  
    ani2
->setDuration(1200);    
    ani2
->setEasingCurve(QEasingCurve::Linear); 
    
    QSignalTransition 
*transition1=state1->addTransition(ui.button,SIGNAL(clicked()),state2);
    
//transition1->addAnimation(ani1);  
    transition1->addAnimation(ani2);
    QSignalTransition 
*transition2=state2->addTransition(ui.button,SIGNAL(clicked()),state1);  
    
//transition2->addAnimation(ani1); 
    transition2->addAnimation(ani2);
    machine
->setInitialState(state1);
    machine
->start();      
}

QTest::
~QTest()
{
}

这个例子很实用
posted on 2013-02-21 21:43 ccsdu2009 阅读(807) 评论(0)  编辑 收藏 引用 所属分类: QT编程

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