QT之QPropertyAnimation简单应用
2023-09-14 09:07:10 时间
头文件:
#ifndef CPROPERTYANIMATIONTEST_H
#define CPROPERTYANIMATIONTEST_H
#include<QWidget>
#include<QPropertyAnimation>
#include <QParallelAnimationGroup>
class CPropertyAnimationTest:public QWidget
{
Q_OBJECT
public:
CPropertyAnimationTest(QWidget *parent=nullptr);
QPropertyAnimation *m_animation;
QPropertyAnimation *m_animation2;
QAnimationGroup *m_animationGroup;
};
#endif // CPROPERTYANIMATIONTEST_H
源文件:
#include "cpropertyanimationtest.h"
#include<QPushButton>
CPropertyAnimationTest::CPropertyAnimationTest(QWidget *parent):QWidget(parent)
{
resize(600,400);
m_animationGroup = new QParallelAnimationGroup(this);
QPushButton *btn=new QPushButton("0",this);
btn->resize(60,30);
QPushButton *btn2=new QPushButton("1",this);
btn2->resize(60,30);
btn2->move(btn->pos().x()+btn->width()+50,0);
QPushButton *start=new QPushButton("开始",this);
start->resize(60,30);
start->move(0,height()-start->height());
m_animation=new QPropertyAnimation;
m_animation->setTargetObject(btn);
m_animation->setPropertyName("pos");
m_animation->setDuration(300);
m_animation2=new QPropertyAnimation;
m_animation2->setTargetObject(btn2);
m_animation2->setPropertyName("pos");
m_animation2->setDuration(300);
m_animationGroup->addAnimation(m_animation);
m_animationGroup->addAnimation(m_animation2);
connect(start,&QPushButton::clicked,this,[=](){
if(btn->pos().x()>width())
{
m_animation->setStartValue(QPoint(0,0));
btn->move(QPoint(0,0));
}
else
m_animation->setStartValue(btn->pos());
m_animation->setEndValue(QPoint(btn->pos().x()+btn->width()+50,0));
if((btn2->pos().x())>width())
{
m_animation2->setStartValue(QPoint(0,0));
btn2->move(QPoint(0,0));
}
else
m_animation2->setStartValue(btn2->pos());
m_animation2->setEndValue(QPoint(btn2->pos().x()+btn2->width()+50,0));
m_animationGroup->start();
});
}
相关文章
- jrtplib接收rtcp_qt tcpsocket 接收数据
- Qt中实现QQ抽屉效果
- C/C++ Qt 运用JSON解析库 [解析篇]
- C/C++ Qt 数据库QSql增删改查组件应用
- C/C++ Qt StandardItemModel 数据模型应用
- C/C++ Qt StatusBar 底部状态栏应用
- Qt运行程序弹出异常窗口解释
- Qt Qml 中动态创建 & 销毁视频容器技巧(一)
- Linux Qt之旅:从入门到精通(linuxqt入门)
- Linux安装Qt:实现轻松易用之旅(linux中安装qt)
- 开发Linux Qt界面开发:拥抱开源世界的应用之旅(linuxqt界面)
- 安装Linux系统,学习QT开发技术(linux安装qt教程)
- Linux安装Qt的步骤指导(linux怎么安装qt)
- Linux编译Qt库:从零开始(linux编译qt库)
- Linux上静态编译Qt应用实现方案(linux静态编译qt)
- 解决Qt连接MySQL的问题(qt连接不上mysql)
- GUI应用Linux下Qt开发GUI应用:实现梦想的开发之路(linux下qt开发)
- 快速搭建Qt环境中的MySQL数据库(qt配置mysql数据库)
- 提高数据处理效率:探究Qt与MySQL数据库的结合应用(qt与mysql数据库)
- Qt在Linux操作系统中的运行和应用(qt运行linux)
- QT开发MSSQL数据库技术实现(qt mssql)
- MySQL与Qt的无缝连接(mysql 连接qt)