如何将Qt实现类似QQ消息震动效果的长尾词功能?
- 内容介绍
- 文章标签
- 相关推荐
本文共计246个文字,预计阅读时间需要1分钟。
在构造函数中初始化动画:cppm_animation=new QPropertyAnimation(this, pos);
实现震动动画:cppvoid Widget::ShakeAnimation(){ QPoint pos=this->pos(); // 动画尚未结束则先立即停止,防止用户连续点击 if (m_animation->state()==QAbstractAnimation::Running) m_animation->stop(); // 防止用户连续点击}
构造里面
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();
}
本文共计246个文字,预计阅读时间需要1分钟。
在构造函数中初始化动画:cppm_animation=new QPropertyAnimation(this, pos);
实现震动动画:cppvoid Widget::ShakeAnimation(){ QPoint pos=this->pos(); // 动画尚未结束则先立即停止,防止用户连续点击 if (m_animation->state()==QAbstractAnimation::Running) m_animation->stop(); // 防止用户连续点击}
构造里面
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();
}

