您的问题是,MaximumWidth并不是一个很好的动画属性,因为它不能直接转换为小部件的实际大小。你最好用
geometry
这会产生更好的效果;例如,它将
QTextEdit
:
class QtTest : public QMainWindow
{
Q_OBJECT
public:
QtTest()
{
m_textEdit = new QTextEdit(this);
};
protected:
QTextEdit *m_textEdit;
virtual void showEvent ( QShowEvent * event )
{
QWidget::showEvent(event);
QPropertyAnimation *animation = new QPropertyAnimation(m_textEdit, "geometry");
animation->setDuration(10000);
animation->setStartValue(QRect(0, 0, 100, 30));
animation->setEndValue(QRect(0, 0, 500, 30));
animation->start();
}
};