Qt开发动画

#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;

posted @   朱小勇  阅读(366)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
点击右上角即可分享
微信分享提示