Qt 动画类 - QPropertyAnimation Class (翻译)

  • QPropertyAnimation Class 官方英文文档【点击前往
  • QPropertyAnimation Class 中文使用介绍【点击前往



QPropertyAnimation Class 简介

[注:详细介绍可以向下翻阅查看]

该类关联的头文件:#include <QPropertyAnimation>

该类的父类是:QVarianAnimation

这个类始创于 QtCore 4.6 版本


属性关系简介

QPropertyAnimation *pAnimation = new QPropertyAnimation(ui->frame, "geometry");

  • 构造函数中 PropertyName :QByteArray [字符串形式的属性名称 例如:"geometry"]
  • 构造函数中 targetObject : QObject * [继承自QObject的UI对象,即你需要作为动画目标的窗体地址,例如:ui->frame]
  • 有 5 个属性继承自 父类(QVariantAnimation)
  • 有 6 个属性继承自爷爷类(QAbstractAnimation)
  • 有 1 个属性继承自祖宗类(QObject)

公共函数简介

公共函数1:获得当前动画类的属性名 
QByteArray propertyName() const

公共函数2:设置当前动画类的属性名
void setPropertyName(const QByteArray & propertyName)

公共函数3:设置当前动画类所操控的对象
void setTargetObject(QObject * target)

公共函数4:获得当前所操控的动画对象
QObject * targetObject() const

  • 13 个公共函数继承自父类(QVariantAnimation)
  • 11 个公共函数继承自爷爷类(QAbstractAnimation)
  • 31 个公共函数继承自祖宗类(QObject)

保护函数简介

保护函数1:事件函数

virtual bool event(QEvent * event)


保护函数2:更新值域
virtual void updateCurrentValue(const QVariant & value)


保护函数3:更新状态
virtual void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState)

  • 5 个保护函数继承自父类(QVariantAnimation)
  • 4 个保护函数继承自爷爷类(QAbstractAnimation)
  • 9 个保护函数继承自祖宗类(QObject)


其它继承的成员

  • 6 public slots inherited from QAbstractAnimation
  • 1 public slot inherited from QObject
  • 1 signal inherited from QVariantAnimation
  • 4 signals inherited from QAbstractAnimation
  • 2 signals inherited from QObject
  • 10 static public members inherited from QObject
  • 5 protected functions inherited from QVariantAnimation
  • 4 protected functions inherited from QAbstractAnimation
  • 9 protected functions inherited from QObject 


QPropertyAnimation Class 详细的说明

这是一个源自 Qt 的动画效果类

QPropertyAnimation 插入 Qt 的属性,将属性保存在 QVariants 当中,

QPropertyAnimation interpolates over Qt properties. As property values are stored in QVariants, 

QPropertyAnimation 继承自 QVariantAnimation, 支持父类的动画效果成为了超级类.

the class inheritsQVariantAnimation, and supports animation of the same meta types as its super class.

窗口部件必须是继承自 QObject, 这是实现动画效果的基本条件.

A class declaring properties must be a QObject. To make it possible to animate a property,

它一定要提供一个控制对象(当然, QPropertyAnimation 本身 也可以成为这个属性值),这样才可以使窗口部件实现动画的效果.

it must provide a setter(so that QPropertyAnimation can set the property's value). Note that this makes it possible to animate many of Qt's widgets.

让我们看一个简单的示例:

Let's look at an example:

QPropertyAnimation *animation = new QPropertyAnimation(myWidget, "geometry");
animation->setDuration(10000);
animation->setStartValue(QRect(0, 0, 100, 30));
animation->setEndValue(QRect(250, 250, 100, 30));
animation->start();

属性名和窗口部件对象,应该是通过构造函数传给动画类的.

the property name and the QObject instance of which property should be animated are passed to the constructor.

构造函数执行完毕之后,你就可以明确的给出开始和结束的QRect属性.

You can then specify the start and end value of the property.

动画的执行过程与类中的属性相关联,动画效果由你的类来实现.

The procedure is equal for properties in classes you have implemented yourself

只要确认好你的 QVariantAnimation 和你的 QVariant 即可.

just check with QVariantAnimation that your QVariant type is supported.


QVarianAnimation类介绍了如何建立一个动画.

The QVarianAnimation class description explains how to set up the animation in detail.

要注意的是,如果没有设置一个起始的坐标值,属性会将当前窗口控件创建的值,作为起始值.

Note, however, that if a start value is not set, the property will start at the value it had when the QPropertyAnimation instance was created.



QPropertyAnimation 有自己的魅力. 

QPropertyAnimation works like a charm on its own, 

相对于复杂的动画例如:包含多个窗口部件对象的,规定使用 QAnimationGroup 类

For complex animations that. for instance.contain several objects, QAnimationGroup is provided.

QAnimationGroup 是包含多个动画的动画组

An animation group is an animation that can contain other animations.

可以在任何时候管理各个动画的播放.

and that can manage when its animations are played.

可以查阅在 QParallelAnimationGroup 里的例子.

Look at QParallelAnimationGroup for an example.


也可以查阅 QVarianAnimation QAnimationGroup 等动画框架.

See also QVarianAnimation, QAnimationGroup, and The Animation Framework.

  • 6
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值