#include <QtCore/QDebug>#include <QtCore/QPropertyAnimation>#include <QtCore/QSignalTransition>#include <QtCore/QStateMachine>#include <QtGui/QApplication>#include <QtGui/QLayout>#include <QtGui/QPushButton>int main( int argc, char** argv ){ QApplication app( argc, argv ); QWidget view; QPushButton* button = new QPushButton( &view ); QHBoxLayout* layout = new QHBoxLayout; layout->addWidget( button ); view.setLayout( layout ); app.setActiveWindow( &view ); view.show(); QStateMachine* stateMachine = new QStateMachine(); QState* hideState = new QState(); hideState->assignProperty( button, "text", "Show" ); QState* showState = new QState(); showState->assignProperty( button, "text", "Hide" ); QPropertyAnimation* showAnimation = new QPropertyAnimation( &view, "size" ); showAnimation->setDuration( 10000 ); showAnimation->setStartValue( QSize( 200, 30 ) ); showAnimation->setEndValue( QSize( 400, 30 ) ); QSignalTransition* showTransition = new QSignalTransition(); showTransition->addAnimation( showAnimation ); hideState->addTransition( showTransition ); hideState->addTransition( button, SIGNAL( clicked() ), showState ); showState->addTransition( button, SIGNAL( clicked() ), hideState ); stateMachine->addState( hideState ); stateMachine->addState( showState ); stateMachine->setInitialState( hideState ); stateMachine->start(); return app.exec();}
#include <QtCore/QDebug>#include <QtCore/QPropertyAnimation>#include <QtCore/QSignalTransition>#include <QtCore/QStateMachine>#include <QtGui/QApplication>#include <QtGui/QLayout>#include <QtGui/QPushButton>int main( int argc, char** argv ){ QApplication app( argc, argv ); QWidget view; QPushButton* button = new QPushButton( &view ); QHBoxLayout* layout = new QHBoxLayout; layout->addWidget( button ); view.setLayout( layout ); app.setActiveWindow( &view ); view.show(); QStateMachine* stateMachine = new QStateMachine(); QState* hideState = new QState(); hideState->assignProperty( button, "text", "Show" ); hideState->assignProperty( &view, "size", QSize (200, 30)); QState* showState = new QState(); showState->assignProperty( button, "text", "Hide" ); showState->assignProperty(&view, "size", QSize (400, 30)); QPropertyAnimation* showAnimation = new QPropertyAnimation(&view, "size" ); showAnimation->setDuration( 1000 ); QSignalTransition* hideTransition = hideState->addTransition( button, SIGNAL( clicked() ), showState ); hideTransition->addAnimation ( showAnimation ); QSignalTransition* showTransition = showState->addTransition( button, SIGNAL( clicked() ), hideState ); showTransition->addAnimation ( showAnimation ); stateMachine->addState( hideState ); stateMachine->addState( showState ); stateMachine->setInitialState( hideState ); stateMachine->start(); return app.exec();}