Qt的显示/隐藏部件动画 [英] Qt Show/Hide widget animation
问题描述
我想实现一个显示/隐藏部件动画。窗口小部件是一个QDockWidget,因此是QMainWindowLayout里面。
I'm trying to implement a show/hide widget animation. The widget is a QDockWidget and therefore is inside the QMainWindowLayout.
使用QPropertyAnimation好好尝试一下似乎工作,我得到的东西看起来就像是:
Using QPropertyAnimation doens't seem to work, I got something looking like that :
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固定高度),但同样的问题。
Unfortunately it doesn't do anything. I tried with other properties (minimumHeight, fixedHeight), but same issue.
我想我没有设置正确使用设计,但我的小部件的布局,即使我以最小的尺寸打我仍然没有任何结果。我应该使用哪种尺寸的政策,如果我想的大小玩?
I thought I didn't setup my widget layout correctly using the designer but even if I play with minimum sizes I still don't have any result. What kind of size policy should I use if I want to play with the size?
我卡住了,这将是如此之大,如果有人能澄清我的问题。我不知道我做错什么......
I'm stuck, it would be so great if someone could clarify my issue. I'm not sure I'm doing anything wrong...
在此先感谢您的帮助,
鲍里斯 -
Thanks in advance for your help, Boris -
推荐答案
顺便说一句,这里是Qt的程序员如何用它在QWidgetAnimator,主要用于停靠小部件的动画,我做的一模一样......
By the way, here is how Qt programmers used it in the QWidgetAnimator, mainly used for animations of dock widgets, I'm doing exactly the same... :
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的显示/隐藏部件动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!