Qt展示/隐藏小部件动画

8

我正在尝试实现一个显示/隐藏小部件动画。该小部件是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);

很遗憾,它什么也没做。我尝试了其他属性(minimumHeight、fixedHeight),但出现了同样的问题。
我以为我没有使用设计师正确设置小部件布局,但即使我调整最小大小,仍然没有任何结果。如果我想调整大小,应该使用什么样的大小策略?
我陷入困境,如果有人能澄清我的问题,那就太好了。我不确定我是否做错了什么...
提前感谢您的帮助, Boris -
1个回答

2
顺便说一下,这是Qt程序员在QWidgetAnimator中使用的方法,主要用于dock小部件的动画效果,我也正在完全相同的方式使用它...:
  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); 

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接