【发布时间】:2015-11-02 14:13:30
【问题描述】:
当鼠标悬停在父窗口小部件上时,我有一个显示/隐藏框架的小动画(在“MyWidget”下方的代码 sn-p 中)。
动画只是改变了框架的 maximumWidth 属性,使框架变得可见,就像一些“滑入效果”。 (框架本身放置在网格布局中。)
我的问题是如何启动动画延迟?示例:鼠标离开事件后500ms开始,所以滑出效果延迟,没有立即开始。
void MyWidget::enterEvent( QEvent * event )
{
//slide-in effect
QPropertyAnimation *animation = new QPropertyAnimation(ui.frame_buttons, "maximumWidth");
animation->setDuration(1000);
animation->setStartValue(ui.frame_buttons->maximumWidth());
animation->setEndValue(100);
animation->setEasingCurve(QEasingCurve::InOutQuad);
animation->start();
}
void MyWidget::leaveEvent( QEvent * event )
{
//slide-out effect
QPropertyAnimation *animation = new QPropertyAnimation(ui.frame_buttons, "maximumWidth");
animation->setDuration(1000);
animation->setStartValue( ui.frame_buttons->maximumWidth() );
animation->setEndValue(0);
animation->setEasingCurve(QEasingCurve::InOutQuad);
//delay start() for a small amount of time
animation->start();
}
【问题讨论】:
-
您可能想使用
void QTimer::singleShot(int msec, QObject * receiver, const char * member)。这被描述为here。 -
看定位 - 太棒了!我会试一试:)
标签: qt qt4 qpropertyanimation