Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Animate widget geometry inside layout



  • Hello,
    I have a problem with animating widget which is placed inside layout. The struct is like fallowing:
    @
    mainWidget with HBoxLayout
    {
    animatedWidget
    otherWidget
    verticalSpacer
    }
    @

    When I decrease the animatedWidget height, the layout does not refresh - otherWidget's top position is always the same, no matter which sizePlicy of animatedWidget do I choose. What is more, when I resize the window, the animatedWidget's height increases to the start value.

    I want to get effect of collapsing widget. Animation code:
    @
    ui->animatedWidget->setMinimumHeight(0);
    ui->animatedWidget->layout()->setEnabled(false);
    QPropertyAnimation *anim = new QPropertyAnimation(ui->animatedWidget, "geometry", 0);
    QRect a = ui->animatedWidget->geometry();
    a.setHeight(0);
    anim->setEndValue(a);
    anim->start(QPropertyAnimation::DeleteWhenStopped);
    @


Log in to reply