【问题标题】:QPropertyAnimation for the "visible" Property of QWidgets only works one wayQWidgets 的“可见”属性的 QPropertyAnimation 只能以一种方式工作
【发布时间】:2016-11-14 14:43:49
【问题描述】:

我有一个任务,我需要执行一系列 PropertyAnimations。其中一个动画是改变 QWidget 的可见性。当我试图隐藏它时,它工作得很好:

QPropertyAnimation *pAnim = new QPropertyAnimation(pWidget, "visible");
pAnim->setStartValue(true);
pAnim->setEndValue(false);
pAnim->start(QAbstractAnimation::DeleteWhenStopped);

但是当我反过来尝试时,什么也没有发生:

QPropertyAnimation *pAnim = new QPropertyAnimation(pWidget, "visible");
pAnim->setStartValue(false);
pAnim->setEndValue(true);
pAnim->start(QAbstractAnimation::DeleteWhenStopped);

我做错了吗?或者这可能是Qt中的一个错误? 如果有帮助,我正在使用 Qt 5.6.1。

【问题讨论】:

    标签: qt animation qt5.6


    【解决方案1】:

    这是我从 Qt 支持中得到的答案:

    bool 不是导致无效 QVariant 的可插值类型,它只是 碰巧转换为假,所以布尔属性永远不能设置为真 默认。[..]

    创建自己的 QAbstractAnimation 子类可能会更好 将属性设置为新值。但是,您当然可以定义您的 bool 的插值函数。例如:

    static QVariant bool_interpolator(const bool& from, const bool& to, qreal 进度){返回进度

    我使用插值器测试了解决方案,它完全按照我的需要工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-02-08
      • 1970-01-01
      • 2016-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多