#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()
{
}
这个例子很实用