#include <QPropertyAnimation>

#include <QDesktopWidget>

//下坠

void MainWindow::on_pushButton_clicked()

{

QPropertyAnimation *pAnimation = new QPropertyAnimation(this, "geometry");

QDesktopWidget *pDesktopWidget = QApplication::desktop();

int x = (pDesktopWidget->availableGeometry().width() - width()) / 2;

int y = (pDesktopWidget->availableGeometry().height() - height()) / 2;

pAnimation->setDuration(1000);

pAnimation->setStartValue(QRect(x, 0, width(), height()));

pAnimation->setEndValue(QRect(x, y, width(), height()));

pAnimation->setEasingCurve(QEasingCurve::OutElastic);

pAnimation->start(QAbstractAnimation::DeleteWhenStopped);

}

//抖动

void MainWindow::on_pushButton_2_clicked()

{

QPropertyAnimation *pAnimation = new QPropertyAnimation(this, "pos");

pAnimation->setDuration(500);

pAnimation->setLoopCount(2);

pAnimation->setKeyValueAt(0, QPoint(geometry().x() - 3, geometry().y() - 3));

pAnimation->setKeyValueAt(0.1, QPoint(geometry().x() + 6, geometry().y() + 6));

pAnimation->setKeyValueAt(0.2, QPoint(geometry().x() - 6, geometry().y() + 6));

pAnimation->setKeyValueAt(0.3, QPoint(geometry().x() + 6, geometry().y() - 6));

pAnimation->setKeyValueAt(0.4, QPoint(geometry().x() - 6, geometry().y() - 6));

pAnimation->setKeyValueAt(0.5, QPoint(geometry().x() + 6, geometry().y() + 6));

pAnimation->setKeyValueAt(0.6, QPoint(geometry().x() - 6, geometry().y() + 6));

pAnimation->setKeyValueAt(0.7, QPoint(geometry().x() + 6, geometry().y() - 6));

pAnimation->setKeyValueAt(0.8, QPoint(geometry().x() - 6, geometry().y() - 6));

pAnimation->setKeyValueAt(0.9, QPoint(geometry().x() + 6, geometry().y() + 6));

pAnimation->setKeyValueAt(1, QPoint(geometry().x() - 3, geometry().y() - 3));

pAnimation->start(QAbstractAnimation::DeleteWhenStopped);

}

//透明度变化

void MainWindow::on_pushButton_3_clicked()

{

QPropertyAnimation *pAnimation = new QPropertyAnimation(this, "windowOpacity");

pAnimation->setDuration(1000);

pAnimation->setKeyValueAt(0, 1);

pAnimation->setKeyValueAt(0.5, 0);

pAnimation->setKeyValueAt(1, 1);

pAnimation->start(QAbstractAnimation::DeleteWhenStopped);

}

转自:http://blog.csdn.net/liang19890820/article/details/51888114

//逐渐出现

QPropertyAnimation *animation = new QPropertyAnimation(this, "windowOpacity");
animation->setDuration(1000);
animation->setStartValue(0);
animation->setEndValue(1);
animation->start();

以上均为窗口动画。

控件动画:【均未成功,不知为何】

1、

QPropertyAnimation *pAnimation = new QPropertyAnimation(ui.groupBox, "opacity");
pAnimation->setDuration(1000);
pAnimation->setStartValue(0);
pAnimation->setEndValue(1);
pAnimation->start(QAbstractAnimation::DeleteWhenStopped);

2、

QGraphicsOpacityEffect* effect = new QGraphicsOpacityEffect(ui.label);
effect->setOpacity(1);
ui.label->setGraphicsEffect(effect);
QPropertyAnimation *pAnimation = new QPropertyAnimation(effect, "opacity",this);
pAnimation->setEasingCurve(QEasingCurve::Linear);
pAnimation->setDuration(10000);
pAnimation->setStartValue(1);
pAnimation->setEndValue(0);
pAnimation->start(QAbstractAnimation::KeepWhenStopped);
delete effect;
delete pAnimation;

Qt开发动画的更多相关文章

  1. Qt开发技术:QCharts(三)QCharts样条曲线图介绍、Demo以及代码详解

    若该文为原创文章,未经允许不得转载原博主博客地址:https://blog.csdn.net/qq21497936原博主博客导航:https://blog.csdn.net/qq21497936/ar ...

  2. Qt开发Activex笔记(一):环境搭建、基础开发流程和演示Demo

    前言   使用C#开发动画,绘图性能跟不上,更换方案使用Qt开发Qt的控件制作成OCX以供C#调用,而activex则是ocx的更高级形式.  QtCreator是没有Active控件项目的,所有需要 ...

  3. win使用MSYS2安装Qt开发环境

    原文链接 MSYS2 下载地址: pacman的具体用法 有pacman的具体使用方法.我们首先对系统升级 我们首先对系统升级 pacman -Syu 就会检测整个系统可以升级的组件,并自动下载安装, ...

  4. qt 窗口动画

    窗口动画 编辑删除转载 2015-10-10 14:50:27 标签:qt渐变动画 一个应用程序通常包含多个动画,例如,你可能希望同时移动许多graphic items或者一个个按照串行的方式的移动他 ...

  5. 细数Qt开发的各种坑(欢迎围观)

    1:Qt的版本多到你数都数不清,多到你开始怀疑人生.从4.6开始到5.8,从MSVC编译器到MINGW编译器,从32位到64位,从Windows到Linux到MAC.MSVC版本还必须安装对应的VS2 ...

  6. 用Qt开发第一个Hello World程序

    配置好Qt的环境变量之后,我们才可以进行下面的通过终端来使用Qt开发这个第一个程序 因为Qt的文件路径不能有中文否则会报错,所以一般都把工程文件都建立在根目录 我们创建的Qt程序包含两个部分:1.GU ...

  7. Qt之动画框架

    简述 Qt动画框架旨在为创建动画和平滑的GUI提供了一种简单的方法.通过Qt动画属性,该框架为部件和其它QObject对象的动画操作提供了非常大的自由性,框架也可以被用于图形视图框架中,动画框架中许多 ...

  8. 第一章 搭建Qt开发环境

    第一章 搭建Qt开发环境 1.到http://download.qt-project.org/archive/上下载Qt的源码包.我下载的是qt-everywhere-opensource-src-4 ...

  9. Ubuntu 12.04下搭建Qt开发环境

    http://download.qt.io/official_releases/qt/ Ubuntu 环境下Gtk与Qt编译环境安装与配置(系统环境是Ubuntu 12.04) 1.配置基础开发环境G ...

随机推荐

  1. head&amp;&amp;tail

    //參考<Linux shell脚本攻略 第2版> 1,head a)打印前10行: ubuntu@VM-62-13-ubuntu:~$ head file b)打印前5行: ubuntu ...

  2. Wireshark使用注意事项

    一直在使用老板的Wireshark,因为4G网络的逐步开通,越来越须要新版Wireshark来解析一些数据包. 在更换了新Wireshark的1.11.3后发现原来能够解析Gb口数据的NSIP不见了 ...

  3. Unity3D学习笔记——组件之Effects(效果/特效)——Particle System(粒子系统)

    Effects:效果/特效. Particle System:粒子系统.可用于创建烟雾.气流.火焰.涟漪等效果. 在Unity3D 3.5版本之后退出了新的shuriken粒子系统:   添加组件之后 ...

  4. PYTHON -创建 表 和 插入 数据

    import sqlite3 conn = sqlite3.connect('y_user_data2.db') cursor = conn.cursor() #create tablecursor. ...

  5. Swift学习笔记(一):No such module 'Cocoa'

    在xcode中创建一个Playground文件, 进行导包操作 ,import Cocoa 却提示No such module 'Cocoa' 原因是该Playground文件的platform 设置 ...

  6. form表单提交中文乱码(前台中文到JAVA后台乱码)问题及解决

    form表单提交中文乱码(前台中文到JAVA后台乱码)问题及解决 一.问题: 页面输入框中的中文内容,在后台乱码,导致搜索功能失效:(详细可以见后面的重现) 二.原因: 浏览器对于数据的默认编码格式为 ...

  7. 创建String字符串的方式与区别

    Java中创建一个字符串的方式有很多种,常见如: String s = new String("riqi"); String s = "riqi"; 但两者有什 ...

  8. C#窗体传值

    整理一下: 1.静态变量传值,非常简单适合简单的非实例的 public calss form1:Form{ public static int A; } public class form2:Form ...

  9. junit5荟萃知识点(一):junit5的组成及安装

    1.什么是junit5? 和之前的junit版本不一样,junit5是由三个模块组成. JUnit 5 = JUnit Platform + JUnit Jupiter + JUnit Vintage ...

  10. Django中间件,信号,缓存

    中间件 django 中的中间件(middleware),在django中,中间件其实就是一个类,在请求到来和结束后,django会根据自己的规则在合适的时机执行中间件中相应的方法. 在django项 ...