Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt Show/Hide widget animation

I'm trying to implement a show/hide widget animation. The widget is a QDockWidget and therefore is inside the QMainWindowLayout.

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

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 -

like image 898
Boris Gougeon Avatar asked Feb 02 '10 02:02

Boris Gougeon


Video Answer


1 Answers

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); 
like image 116
Boris Gougeon Avatar answered Sep 20 '22 20:09

Boris Gougeon