Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QHBoxLayout doesn't automatically update and adjust the size when animate a widget inside the layout with "size" property

QHBoxLayout doesn't automatically update and adjust the size when animate a widget inside the layout with "size" property

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 4.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    brucewuu
    wrote on last edited by
    #1

    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 ~~

    wish all the best to you from
    bruce wuu
    Autodesk China Inc.
    SW Developer
    M&E Product Developerment Group
    Work 137 6411 8921
    bruce.wu@autodesk.com

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dialingo
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        brucewuu
        wrote on last edited by
        #3

        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 .

        wish all the best to you from
        bruce wuu
        Autodesk China Inc.
        SW Developer
        M&E Product Developerment Group
        Work 137 6411 8921
        bruce.wu@autodesk.com

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved