您的位置:首页 > 编程语言 > Qt开发

【Qt动画框架】

2015-12-04 14:35 453 查看
虽然现在大多数项目的动画都是用QML在做了,反正了解了解也没什么坏处,或许以后也用得到。

一 Qt动画框架

缺少一张图。。。公司网速太慢,传不上去。

(其实也就是Qt动画框架类,了解即可)

Qt动画框架类

QAbstractAnimation 所有动画类的基类

QAnimationGroup 动画容器类的抽象基类 (记忆一下,挺重要)

——QParallelAnimationGroup 并行动画容器 (多个动画同时运行)

——QSequentialAnimationGroup 串行动画容器 (动画一个接一个的运行)

QEasingCurve 动画控制的缓和曲线类(动画的运行方式(参考手机界面弹出方式))

QPauseAnimation 对象暂停延时

QPropertyAnimation Qt动画属性操作(重要,用于同QObject的属性通信(比如widget的一些大小和坐标))

QTimeLine 动画控制的时间片类

QVariantAnimation 动画类的抽象基类

Qt动画的例子

这里就不多说废话了,直接上例子,看看里面的一些方法和机制

(也都是网上常有的一些例子)

1.窗口的移动

**这里就看看这几个方法的使用

.setDuration

.setStartValue

.setEndValue**

//创建一个按钮
QPushButton button("Animated Button");
button.show();

//创建一个动画的属性对象(该动画,基于button)
QPropertyAnimation animation(&button, "geometry");
//关于这个构造函数,我已开始有很多问题
//第一个参数,哪个控件
//第二个参数,是该控件的某个属性(动画也就是基于该属性的变化)
animation.setDuration(10000);
//设置动画的持续时间————动画从开始到结束的时间
animation.setStartValue(QRect(0, 0, 150, 50));
//设置起始位置
animation.setEndValue(QRect(250, 250, 100, 30));
//设置结束位置
animation.start();


2.窗口的移动—升级1

**主要看看这个方法的使用

.setKeyValueAt**

QPushButton button("Animated Button");
button.show();

QPropertyAnimation animation(&button, "geometry");
animation.setDuration(10000);
//动画设置10s
animation.setKeyValueAt(0, QRect(0, 0, 100, 30));
animation.setKeyValueAt(0.8, QRect(250, 250, 100, 30));
animation.setKeyValueAt(1, QRect(0, 0, 100, 30));
//前8s 向右下移动
//后2s 向左上移动
animation.start();


3.窗口的移动—升级2

**主要关注这些方法的使用

.setEasingCurve**

QPushButton button("Animated Button");
button.show();

QPropertyAnimation animation(&button, "geometry");
animation.setDuration(3000);

animation.setStartValue(QRect(0, 0, 100, 30));
animation.setEndValue(QRect(250, 250, 100, 30));

animation.setEasingCurve(QEasingCurve::OutBounce);
//控制移动的轨迹(回弹)
animation.start();


4.窗口的移动—升级3

多个动画窗口,这里就要注意

QSequentialAnimationGroup

QParallelAnimationGroup

这两个类的使用

并行动画

QPushButton *bonnie = new QPushButton("Bonnie");
bonnie->show();

QPushButton *clyde = new QPushButton("Clyde");
clyde->show();

QPropertyAnimation *anim1 = new QPropertyAnimation(bonnie, "geometry");
// 这里的动画是基于bonnie的
QPropertyAnimation *anim2 = new QPropertyAnimation(clyde, "geometry");
//这里的动画是基于clyde的

QParallelAnimationGroup *group = new QParallelAnimationGroup;
//这里注意啦:这就是并行输出,同时的
group->addAnimation(anim1);
group->addAnimation(anim2);
group->start();


串行动画

QPushButton button("Animated Button");
button.show();

QPropertyAnimation anim1(&button, "geometry");
anim1.setDuration(3000);
anim1.setStartValue(QRect(0, 0, 100, 30));
anim1.setEndValue(QRect(500, 500, 100, 30));
QPropertyAnimation anim2(&button, "geometry");

anim2.setDuration(3000);
anim2.setStartValue(QRect(500, 500, 100, 30));
anim2.setEndValue(QRect(1000, 500, 100, 30));

QSequentialAnimationGroup group;
//这里就是串行啦
group.addAnimation(&anim1);
group.addAnimation(&anim2);
group.start();


这里遗留一个问题,就是状态机 和 动画的协作。。。下章写。。。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: