QHBoxLayout doesn't automatically update and adjust the size when animate a widget inside the layout with "size" property
-
wrote on 12 Jul 2011, 05:29 last edited by
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(startAnimation())); 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 ~~ -
wrote on 12 Jul 2011, 07:08 last edited by
There is a conceptual conflict. You ask the layoutmanager to manage the geometry of a widget. That means you can not manually change the geometry of the widget and you can not use an animation on it.
You can try to animate the properties that are used by the layout manager, like minimumSize() or maximumSize(). I haven't tried it though. -
wrote on 12 Jul 2011, 07:18 last edited by
actually I can do this by adding another animation on the rightWidget with "geometry" properties , but I think like QHBoxLayout , it should automatically resize when the size of one child widget changes .
1/3