class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
~Widget();
private:
void resizeEvent(QResizeEvent* event);
private:
QStateMachine* mMachine;
QSignalTransition* mTransition;
QState* mMaxState;
QState* mMinState;
QPushButton* mButton;
bool mResized;
};
Widget::Widget(QWidget *parent):
QWidget(parent)
{
mResized = false;
resize(640,480);
}
Widget::~Widget()
{
}
void Widget::resizeEvent(QResizeEvent* event)
{
if(size().height() == 0)
{
close();
return;
}
if(mResized)
return;
mButton = new QPushButton(this);
mButton->setText("Click");
mResized = true;
QPoint p = pos();
QSize s = size();
mMachine = new QStateMachine(this);
mMaxState = new QState(mMachine);
mMaxState->assignProperty(this,"geometry",QRect(p,s));
//connect(mMachine,SIGNAL(finished()),this,SLOT(callClose()));
mMinState = new QState(mMachine);
mMinState->assignProperty(this,"geometry",QRect(p.x(),p.y()+s.height()/2,s.width(),0));
//connect(mMinState,SIGNAL(entered()),this,SLOT(callClose()));
mMachine->setInitialState(mMaxState);
QPropertyAnimation* ani1 = new QPropertyAnimation(this,"geometry");
ani1->setDuration(300);
ani1->setEasingCurve(QEasingCurve::Linear);
QSignalTransition* transition = mMaxState->addTransition(mButton,SIGNAL(clicked()),mMinState);
transition->addAnimation(ani1);
mMachine->start();
}
不过有2个问题,当动画结束的时候,和这句相关connect(mMinState,SIGNAL(entered()),this,SLOT(callClose()));
可以退出程序
但是动画没执行 有空看下
setSizeConstraint(QLayout::SetNoConstraint);