0
当鼠标悬停在父窗口小部件(在“MyWidget”下面的代码片段中)时,我有一个小动画显示/隐藏框架。启动QPropertyAnimation延迟
动画只是简单地改变框架的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)'。这是[这里]描述(http://doc.qt.io/qt-4.8/qtimer.html#singleShot)。 – Mezzo
Look targeting - 太棒了!我会试一下 :) – 550