Qt模仿QQ震动效果

构造里面
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();
}
 
  
很简单的功能,希望大家也分享下关于Qt的小知识
 
 

你可能感兴趣的:(QT)