PDA

View Full Version : QHBoxLayout doesn’t automatically update and adjust the size when animate a widget in



brucewuu
12th July 2011, 09:19
hi all I want to animate one widget inside a QHBoxLayout , with QPropertyAnimation(XXX,“size”) , while when the animation start , the other widgets stay on their own original positon ,I want them to automatically adjust size and layout , see the following code .

#include "window.h"

Window::Window(QWidget *parent)
: QWidget(parent)
{
fLayout = new QHBoxLayout(this);
fLeftWidget = new QWidget;
fRightWidget = new QWidget;
fLayout->addWidget(fLeftWidget);
fLayout->addWidget(fRightWidget);

QVBoxLayout *leftLayout = new QVBoxLayout(fLeftWidget);
leftLayout->addWidget(new QLineEdit());
leftLayout->addWidget(new QTextEdit);
leftLayout->addWidget(new QPushButton("submit"));

QVBoxLayout *rightLayout = new QVBoxLayout(fRightWidget);
QPushButton *button = new QPushButton("click me ");
connect(button,SIGNAL(clicked()),this,SLOT(startAn imation()));
rightLayout->addWidget(button);
rightLayout->addWidget(new QTextEdit);

}


Window::~Window()
{

}


void Window::startAnimation()
{
QPropertyAnimation *animation = new QPropertyAnimation(fLeftWidget,"size");
animation->setDuration(200);
animation->setStartValue(fLeftWidget->size());
animation->setEndValue(QSize(0,fLeftWidget->size().height()));
animation->start();
}

I have tried to call QBoxLayout::invalidate , but failed to get the effect , what should I do ? thanks ~~