我正在尝试实现显示/隐藏小部件动画。该小部件是一个 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),但同样的问题。
我以为我没有使用设计器正确设置我的小部件布局,但即使我使用最小尺寸,我仍然没有任何结果。如果我想玩尺码,我应该使用什么样的尺码政策?
我被卡住了,如果有人能澄清我的问题,那就太好了。我不确定我做错了什么......
在此先感谢您的帮助,
鲍里斯——
最佳答案
顺便说一下,这里是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);
关于Qt 显示/隐藏小部件动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2181566/