QPropertyAnimation 几行代码快速制作流畅的动画效果
2018-01-08 10:30
585 查看
原文地址::http://blog.csdn.net/csnd_ayo/article/details/53790217
相关文章
1、Qt 动画类 - QPropertyAnimation Class (翻译)----http://blog.csdn.net/csnd_ayo/article/details/53770611
2、Qt简介----http://blog.csdn.net/csnd_ayo/article/details/70170882
QPropertyAnimation Class 官方英文文档【点击前往】
QPropertyAnimation Class 中文译文文档【点击前往】
QPropertyAnimation Class 是一个控制动画效果的类,诞生自 Qt
4.6 版本。 该类继承自 QVarianAnimation,并支持其它基类相同的动画类,例如:QAnimationGroup 动画组类,该类仅支持继承自 QObject 类的窗口部件。
用例子来讲述各个功能,直观,立竿见影。
头文件
[cpp] view
plain copy
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
cpp文件
[cpp] view
plain copy
#include <QPropertyAnimation>
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
/* 声明动画类,并将控制对象 this (this一定是继承自QObject的窗口部件) 以及属性名 "geometry" 传入构造函数 */
QPropertyAnimation* animation = new QPropertyAnimation(this, "geometry");
/* 设置动画持续时长为 2 秒钟 */
animation->setDuration(2000);
/* 设置动画的起始状态 起始点 (1,2) 起始大小 (3,4) */
animation->setStartValue(QRect(1, 2, 3, 4));
/* 设置动画的结束状态 结束点 (100,200) 结束大小 (300,400) */
animation->setEndValue(QRect(100, 200, 300, 400));
/* 设置动画效果 */
animation->setEasingCurve(QEasingCurve::OutInExpo);
/* 开始执行动画 QAbstractAnimation::DeleteWhenStopped 动画结束后进行自清理(效果就好像智能指针里的自动delete animation) */
animation->start(QAbstractAnimation::DeleteWhenStopped);
}
MainWindow::~MainWindow()
{
delete ui;
}
QPropertyAnimation 声明的时候
可以传入的属性分别有 pos(位置)、windowOpacity(透明度)
位置示例
[cpp] view
plain copy
void OEasyWebNotice::onShow() {
QRect rect = QApplication::desktop()->availableGeometry();
const int &endy = rect.height() - height();
QPropertyAnimation *animation= new QPropertyAnimation(this,"pos");
animation->setDuration(2000);
animation->setStartValue(QPoint(rect.width() - width(), rect.height()));
animation->setEndValue(QPoint(rect.width() - width(), endy));
animation->setEasingCurve(QEasingCurve::OutCubic);
connect(animation, SIGNAL(finished()),
this, SLOT(animationFinished()));
show();
animation->start(QAbstractAnimation::DeleteWhenStopped);
}
透明度示例
[cpp] view
plain copy
void OEasyWebNotice::onClose(void) {
disconnect(closeButton_.get(),SIGNAL(clicked()),
this, SLOT(onClose()));
QPropertyAnimation* animation = new QPropertyAnimation(this, "windowOpacity");
animation->setDuration(1000);
animation->setStartValue(1);
animation->setEndValue(0);
animation->setEasingCurve(QEasingCurve::InCirc);
connect(animation, SIGNAL(finished()),
this, SLOT(deleteLater()));
show();
animation->start(QAbstractAnimation::DeleteWhenStopped);
}
关于 QPropertyAnimation 我为大家推荐一个我写的项目
国内开源社区 国际开源社区
版权声明:分享得以延续,交流方知彼此。作者:_OE_ 博客地址:http://blog.csdn.net/csnd_ayo
本文已收录于以下专栏:
《Qter
必知必会》
相关文章
1、Qt 动画类 - QPropertyAnimation Class (翻译)----http://blog.csdn.net/csnd_ayo/article/details/53770611
2、Qt简介----http://blog.csdn.net/csnd_ayo/article/details/70170882
QPropertyAnimation Class 官方英文文档【点击前往】
QPropertyAnimation Class 中文译文文档【点击前往】
简介
QPropertyAnimation Class 是一个控制动画效果的类,诞生自 Qt4.6 版本。 该类继承自 QVarianAnimation,并支持其它基类相同的动画类,例如:QAnimationGroup 动画组类,该类仅支持继承自 QObject 类的窗口部件。
以例代劳
用例子来讲述各个功能,直观,立竿见影。头文件
[cpp] view
plain copy
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
cpp文件
[cpp] view
plain copy
#include <QPropertyAnimation>
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
/* 声明动画类,并将控制对象 this (this一定是继承自QObject的窗口部件) 以及属性名 "geometry" 传入构造函数 */
QPropertyAnimation* animation = new QPropertyAnimation(this, "geometry");
/* 设置动画持续时长为 2 秒钟 */
animation->setDuration(2000);
/* 设置动画的起始状态 起始点 (1,2) 起始大小 (3,4) */
animation->setStartValue(QRect(1, 2, 3, 4));
/* 设置动画的结束状态 结束点 (100,200) 结束大小 (300,400) */
animation->setEndValue(QRect(100, 200, 300, 400));
/* 设置动画效果 */
animation->setEasingCurve(QEasingCurve::OutInExpo);
/* 开始执行动画 QAbstractAnimation::DeleteWhenStopped 动画结束后进行自清理(效果就好像智能指针里的自动delete animation) */
animation->start(QAbstractAnimation::DeleteWhenStopped);
}
MainWindow::~MainWindow()
{
delete ui;
}
QPropertyAnimation 声明的时候
可以传入的属性分别有 pos(位置)、windowOpacity(透明度)
位置示例
[cpp] view
plain copy
void OEasyWebNotice::onShow() {
QRect rect = QApplication::desktop()->availableGeometry();
const int &endy = rect.height() - height();
QPropertyAnimation *animation= new QPropertyAnimation(this,"pos");
animation->setDuration(2000);
animation->setStartValue(QPoint(rect.width() - width(), rect.height()));
animation->setEndValue(QPoint(rect.width() - width(), endy));
animation->setEasingCurve(QEasingCurve::OutCubic);
connect(animation, SIGNAL(finished()),
this, SLOT(animationFinished()));
show();
animation->start(QAbstractAnimation::DeleteWhenStopped);
}
透明度示例
[cpp] view
plain copy
void OEasyWebNotice::onClose(void) {
disconnect(closeButton_.get(),SIGNAL(clicked()),
this, SLOT(onClose()));
QPropertyAnimation* animation = new QPropertyAnimation(this, "windowOpacity");
animation->setDuration(1000);
animation->setStartValue(1);
animation->setEndValue(0);
animation->setEasingCurve(QEasingCurve::InCirc);
connect(animation, SIGNAL(finished()),
this, SLOT(deleteLater()));
show();
animation->start(QAbstractAnimation::DeleteWhenStopped);
}
关于 QPropertyAnimation 我为大家推荐一个我写的项目
国内开源社区 国际开源社区
版权声明:分享得以延续,交流方知彼此。作者:_OE_ 博客地址:http://blog.csdn.net/csnd_ayo
本文已收录于以下专栏:
《Qter
必知必会》
相关文章推荐
- QPropertyAnimation 几行代码快速制作流畅的动画效果
- QPropertyAnimation 几行代码快速制作流畅的动画效果
- 【图解】通过Expression Blend快速制作具有物理效果的动画游戏
- Android动画效果之Property Animation进阶(属性动画)
- 分别在XML文件、Java代码中实现动画效果 Animation(带示例)
- requestAnimationFrame 实现更流畅,高效的动画效果
- android动画效果之Property Animation进阶(属性动画)
- Android动画效果之Property Animation(属性动画)
- Animation制作动画组件效果
- android开发游记:通过xml配置快速实现点击热点效果和渐变动画(不用java代码)
- 利用JQuery动画制作滑动菜单项效果实现步骤及代码
- 制作动画效果:《CSS3 Animation》
- 幻灯片的JQuqey的制作效果,只要几行代码
- 安卓开发20:动画之Animation 详细使用-主要通过java代码实现动画效果
- Android动画效果之Property Animation进阶(属性动画)
- Animation动画效果(代码实现)
- 几行代码实现tab+fragment+viewpager---还有酷炫的动画效果哦
- Qt动画效果的实现,QPropertyAnimation
- 常见的四种Animation详解(深入可以制作效果动画)
- CSS Animatie是一款在线制作CSS3动画的工具,可以在线直接制作CSS3动画效果,生成代码