Qt显示/隐藏小部件动画

Bor*_*eon 6 animation qt qwidget

我正在尝试实现一个显示/隐藏小部件动画.小部件是QDockWidget,因此位于QMainWindowLayout内.

使用QPropertyAnimation似乎不起作用,我得到的东西看起来像这样:

m_listViewDock->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
QPropertyAnimation* animation = new QPropertyAnimation(m_listViewDock, "geometry", m_listViewDock);

animation->setDuration(1000);

QRect g = m_listViewDock->geometry();
animation->setStartState(g);
g.setHeight(80);
animation->setEndState(g);
animation->start(QAbstractAnimation::DeleteWhenStopped);
Run Code Online (Sandbox Code Playgroud)

不幸的是它没有做任何事情.我尝试过其他属性(minimumHeight,fixedHeight),但同样的问题.

我以为我没有使用设计师正确设置我的小部件布局,但即使我玩最小尺寸我仍然没有任何结果.如果我想玩大小,我应该使用什么样的大小政策?

我被困住了,如果有人能澄清我的问题那就太棒了.我不确定我做错了什么......

在此先感谢您的帮助,鲍里斯 -

Bor*_*eon 2

顺便说一句,这是 Qt 程序员如何在 QWidgetAnimator 中使用它,主要用于停靠小部件的动画,我正在做完全相同的事情......:

  const QRect final_geometry = _final_geometry.isValid() || widget->isWindow() ? _final_geometry :
        QRect(QPoint(-500 - widget->width(), -500 - widget->height()), widget->size());

#ifndef QT_NO_ANIMATION
    AnimationMap::const_iterator it = m_animation_map.constFind(widget);
    if (it != m_animation_map.constEnd() && (*it)->endValue().toRect() == final_geometry)
        return;

    QPropertyAnimation *anim = new QPropertyAnimation(widget, "geometry", widget);
    anim->setDuration(animate ? 200 : 0);
    anim->setEasingCurve(QEasingCurve::InOutQuad);
    anim->setEndValue(final_geometry);
    m_animation_map[widget] = anim;
    connect(anim, SIGNAL(finished()), SLOT(animationFinished()));
    anim->start(QPropertyAnimation::DeleteWhenStopped); 
Run Code Online (Sandbox Code Playgroud)