Qt 显示/隐藏小部件动画

标签 qt animation qwidget

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

相关文章:

qt - 为什么将 Widget 嵌入到基于 Qml 的应用程序中是不好的想法

qt - 在 Mac OSX Lion/make 上安装 Qt 丢失

android - Android 中用于转换的自定义动画对象?

python - 使用 pywinauto 查找 qwidget 对象文本

ios - 防止自定义容器中的 UINavigationBar 动画

java - 为什么我的动画不可见?

qt - 当子窗口隐藏时调整 qt 小部件的大小

c++ - QSerialPort::readLine 在 MS Windows 上无法正常工作

c++ - 无法在 Mac 中使用 Boost + Qt

c++ - 为什么写入此套接字会丢弃读取缓冲区(这是真的发生了什么)?