Qt 显示/隐藏小部件动画
我正在尝试实现显示/隐藏小部件动画。该小部件是一个 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),但出现同样的问题。
我以为我没有使用设计器正确设置小部件布局,但即使我使用最小尺寸,我仍然没有任何结果。如果我想玩转尺寸,我应该使用什么样的尺寸策略?
我被困住了,如果有人能澄清我的问题那就太好了。我不确定我做错了什么...
提前感谢您的帮助, 鲍里斯-
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 -
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
顺便说一句,这是 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... :