qt5--动画
位置和大小动画
this->resize(500,500); QLabel* label=new QLabel("动画",this); label->move(10,10); label->setStyleSheet("background-color: rgb(255, 251, 100)"); //设置背景色 QPropertyAnimation *animation = new QPropertyAnimation(label, "geometry"); //创建属性动画对象 //参数1:动画作用的QObject对象;也可以用setTargetObject函数来设置 //参数2:要用来动画的属性;也可以用setPropertyName函数来设置 animation->setDuration(10000); //设置这个动画的时长--单位:毫秒 int n=animation->duration(); //返回动画的作用时间--单位:毫秒 animation->setStartValue(QRect(0, 0, 200, 200)); //设置动画的起始坐标与大小 animation->setKeyValueAt(0.4, QRect(20, 250, 20, 30)); //在40%的位置插入 animation->setEndValue(QRect(450, 450, 100, 30)); //设置动画的结束坐标与大小 animation->setEasingCurve(QEasingCurve::OutBounce); //设置动画效果 //QEasingCurve枚举值参看assistant.exe animation->start(); //动画开始
动画组
this->resize(500,500); QLabel* label=new QLabel("AAA",this); QLabel* label1=new QLabel("BBB",this); label->setStyleSheet("background-color: rgb(255, 0, 0)"); label1->setStyleSheet("background-color: rgb(0, 0, 255)"); QPropertyAnimation *animation = new QPropertyAnimation(label, "geometry"); QPropertyAnimation *animation1 = new QPropertyAnimation(label1, "geometry"); animation->setDuration(10000); animation1->setDuration(10000); animation->setStartValue(QRect(0, 0, 100, 30)); animation->setEndValue(QRect(450, 450, 100, 30)); animation1->setStartValue(QRect(450, 450, 100, 30)); animation1->setEndValue(QRect(0, 0, 100, 30)); /*动画组分为两种分别为串行和并行,对应于QAnimationGroup的两个子类QSequentialAnimationGroup和QParallelAnimationGroup 串行动画第一个执行完毕才会执行第二个;并行动画,一起执行 需要 #include <QSequentialAnimationGroup> 或#include <QParallelAnimationGroup> */ QSequentialAnimationGroup* group=new QSequentialAnimationGroup; //创建动画组 group->addAnimation(animation); //添加动画 group->addAnimation(animation1); group->start(); //启动动画组
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)