如何动画隐藏/显示QVBoxLayout小部件

swd*_*dev 6 layout animation qt pyqt show-hide

我有一个QWidget子类的水平布局使用QHBoxLayout: 布局

我想在滑动动画中隐藏/显示顶部小部件.我读过这篇文章,我知道我必须使用QPropertyAnimation.坦率地说,谷歌的结果不是很好.

对代码示例的任何建议或者可能链接到文章?

Nej*_*jat 7

您可以maximumHeight在动画中更改顶部窗口小部件的属性.

隐藏顶部小部件:

QPropertyAnimation *animation = new QPropertyAnimation(ui->topWidget, "maximumHeight");
animation->setDuration(1000);
animation->setStartValue(500);
animation->setEndValue(0);

animation->start();
Run Code Online (Sandbox Code Playgroud)

用于显示顶部小部件:

QPropertyAnimation *animation = new QPropertyAnimation(ui->topWidget, "maximumHeight");
animation->setDuration(1000);
animation->setStartValue(0);
animation->setEndValue(500);

animation->start();
Run Code Online (Sandbox Code Playgroud)