How to animate hiding/showing of a QVBoxLayout widget

对着背影说爱祢 提交于 2019-12-21 13:29:08

问题


I have this horizontal layout of a QWidget subclass using QHBoxLayout:

I would like the top widget to hide/show in sliding animation. I have read this article, and I know that I have to use QPropertyAnimation. Frankly, not a good Google result come up.

Any suggestion for code example or maybe link to an article?


回答1:


You can change the maximumHeight property of the top widget in an animation.

For hiding the top widget :

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

animation->start();

for showing the top widget :

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

animation->start();


来源:https://stackoverflow.com/questions/24106177/how-to-animate-hiding-showing-of-a-qvboxlayout-widget

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!