当前位置 : 主页 > 网络编程 > net编程 >

Qt模仿QQ震动效果

来源:互联网 收集:自由互联 发布时间:2023-09-07
构造里面 m_animation = new QPropertyAnimation ( this , "pos" ); void Widget::ShakeAnimation () { QPoint pos = this - pos (); //动画还没有结束就先立马停止,防止用户不停的点击 if ( m_animation - state () == QPropert

构造里面

m_animation = new QPropertyAnimation(this,"pos");
void Widget::ShakeAnimation()
{
QPoint pos = this->pos();
//动画还没有结束就先立马停止,防止用户不停的点击
if(m_animation->state() == QPropertyAnimation::Running)
{
m_animation->stop();
}
m_animation->setDuration(500);
m_animation->setStartValue(pos);
m_animation->setKeyValueAt(0.1,pos + QPoint(-5,-5));
m_animation->setKeyValueAt(0.2,pos + QPoint(0,-5));
m_animation->setKeyValueAt(0.3,pos + QPoint(5,0));
m_animation->setKeyValueAt(0.4,pos + QPoint(6,1));
m_animation->setKeyValueAt(0.5,pos + QPoint(7,-7));
m_animation->setKeyValueAt(0.6,pos + QPoint(-6,6));
m_animation->setKeyValueAt(0.7,pos + QPoint(-8,0));
m_animation->setKeyValueAt(0.8,pos + QPoint(0,6));
m_animation->setKeyValueAt(0.9,pos + QPoint(4,2));
m_animation->setEndValue(pos);
m_animation->start();
}


上一篇:C# 字符串string与char数组互转!
下一篇:没有了
网友评论