问题
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