【问题标题】:How to animate hiding/showing of a QVBoxLayout widget如何动画隐藏/显示 QVBoxLayout 小部件
【发布时间】:2014-07-29 03:51:51
【问题描述】:

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

我希望顶部小部件在滑动动画中隐藏/显示。我读过this article,我知道我必须使用QPropertyAnimation。坦率地说,Google 的结果并不好。

对代码示例或文章链接有什么建议吗?

【问题讨论】:

    标签: qt animation layout pyqt show-hide


    【解决方案1】:

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

    用于隐藏顶部小部件:

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

    用于显示顶部小部件:

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

    【讨论】:

    • 嗯...我想我现在了解 QPropertyAnimation 的工作原理了。明天早上会检查并在此处报告。但我认为将其标记为已回答是省事
    • 值得注意的是上面的代码是c++代码,不是Python代码(问题标记为pyqt)
    猜你喜欢
    • 1970-01-01
    • 2019-07-03
    • 2012-03-07
    • 2021-06-15
    • 2021-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多