2010-02-02 112 views
6

我试图实现显示/隐藏部件动画。该小部件是一个QDockWidget,因此在QMainWindowLayout中。Qt显示/隐藏部件动画

使用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),但同样的问题。

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

我被卡住了,如果有人能够澄清我的问题,那将会非常棒。我不知道我做错了什么......在您的帮助, 鲍里斯

谢谢 -

回答

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);