直播软件app开发,实现图片之间的交换动画
直播软件app开发,实现图片之间的交换动画
.h
1 | <br>#ifndef WIDGET_H<br>#define WIDGET_H<br># include <QWidget><br># include <QPushButton><br># include <QLineEdit><br> class Widget : public QWidget<br>{<br> Q_OBJECT<br> public :<br> Widget(QWidget *parent = nullptr);<br> ~Widget();<br> void CreateBtnWgt();<br> private slots:<br> void onAnimationClicked();<br> private :<br> void changeBtnPostion(QPushButton *btn1,QPushButton *btn2);<br> private :<br> QLineEdit *line1=nullptr;<br> QLineEdit *line2=nullptr;<br> QLineEdit *line3=nullptr;<br> QLineEdit *line4=nullptr;<br> QLineEdit *line5=nullptr;<br> QPushButton *btn1=nullptr;<br> QPushButton *btn2=nullptr;<br> QPushButton *btn3=nullptr;<br> QPushButton *btn4=nullptr;<br> QPushButton *btn5=nullptr;<br> QWidget *btnWgt=nullptr;<br>};<br># endif // WIDGET_H |
.cpp
1 | <br># include "widget.h" <br># include <iostream><br># include <qdebug.h><br># include <QHBoxLayout><br># include <QPropertyAnimation><br># include <QValidator><br># include <QTimer><br># include <QTime><br># include <thread><br>Widget::Widget(QWidget *parent)<br> : QWidget(parent)<br>{<br> CreateBtnWgt();<br> QWidget *titleWgt= new QWidget(this);<br> QPushButton *animationBtn= new QPushButton(tr( "Sort" ),this);<br> animationBtn->setFixedSize(80,27);<br> QHBoxLayout *titleLayout= new QHBoxLayout(this);<br> line1= new QLineEdit(this);<br> line2= new QLineEdit(this);<br> line3= new QLineEdit(this);<br> line4= new QLineEdit(this);<br> line5= new QLineEdit(this);<br> line1->setValidator( new QIntValidator());<br> line2->setValidator( new QIntValidator());<br> line3->setValidator( new QIntValidator());<br> line4->setValidator( new QIntValidator());<br> line5->setValidator( new QIntValidator());<br> line1->setFixedWidth(100);<br> line2->setFixedWidth(100);<br> line3->setFixedWidth(100);<br> line4->setFixedWidth(100);<br> line5->setFixedWidth(100);<br> titleLayout->addWidget(line1);<br> titleLayout->addWidget(line2);<br> titleLayout->addWidget(line3);<br> titleLayout->addWidget(line4);<br> titleLayout->addWidget(line5);<br> titleLayout->addWidget(animationBtn);<br> titleLayout->setMargin(5);<br> titleLayout->setSpacing(5);<br> titleWgt->setLayout(titleLayout);<br> titleWgt->setFixedHeight(50);<br> QVBoxLayout *mainLayout= new QVBoxLayout(this);<br> mainLayout->addWidget(titleWgt);<br> mainLayout->addWidget(btnWgt);<br> mainLayout->setMargin(0);<br> mainLayout->setSpacing(0);<br> this->setLayout(mainLayout);<br> connect(animationBtn,&QPushButton::clicked,this,&Widget::onAnimationClicked);<br> this->resize(800,600);<br> //qDebug()<<"ans::"<<ans;<br>}<br>Widget::~Widget()<br>{<br>}<br>void Widget::CreateBtnWgt()<br>{<br> QFont textFont;<br> textFont.setPointSize(20);<br> textFont.setFamily("Microsoft YaHei");<br> btn1=new QPushButton(this);<br> btn2=new QPushButton(this);<br> btn3=new QPushButton(this);<br> btn4=new QPushButton(this);<br> btn5=new QPushButton(this);<br> btn1->setFixedSize(100,150);<br> btn2->setFixedSize(100,150);<br> btn3->setFixedSize(100,150);<br> btn4->setFixedSize(100,150);<br> btn5->setFixedSize(100,150);<br> btn1->setStyleSheet("border-radius:5px;");<br> btn2->setStyleSheet("border-radius:5px;background-color:rgb(69,133,254);");<br> btn3->setStyleSheet("border-radius:5px;background-color:rgb(69,133,254);");<br> btn4->setStyleSheet("border-radius:5px;background-color:rgb(69,133,254);");<br> btn5->setStyleSheet("border-radius:5px;background-color:rgb(69,133,254);");<br> btn1->setFont(textFont);<br> btn2->setFont(textFont);<br> btn3->setFont(textFont);<br> btn4->setFont(textFont);<br> btn5->setFont(textFont);<br> //btn1->move(50,250);<br> btnWgt=new QWidget(this);<br> QHBoxLayout *btnLayout=new QHBoxLayout(this);<br> btnLayout->addWidget(btn1);<br> btnLayout->addWidget(btn2);<br> btnLayout->addWidget(btn3);<br> btnLayout->addWidget(btn4);<br> btnLayout->addWidget(btn5);<br> btnLayout->setMargin(20);<br> btnLayout->setSpacing(50);<br> btnWgt->setLayout(btnLayout);<br>}<br>void Widget::onAnimationClicked()<br>{<br> btn1->setText(line1->text());<br> btn2->setText(line2->text());<br> btn3->setText(line3->text());<br> btn4->setText(line4->text());<br> btn5->setText(line5->text());<br> changeBtnPostion(btn1,btn5);<br>}<br>void Widget::changeBtnPostion(QPushButton *bt1, QPushButton *bt2)<br>{<br> QPropertyAnimation *animation1 = new QPropertyAnimation(bt1, "geometry");<br> int x1=bt1->pos().x();<br> int y1=bt1->pos().y();<br> animation1->setDuration(500);<br> animation1->setStartValue(QRect(bt1->pos().x(),bt1->pos().y(), bt1->width(), bt1->height()));<br> animation1->setEndValue(QRect(bt1->pos().x(),bt1->pos().y()+200, bt1->width(), bt1->height()));<br> animation1->setEasingCurve(QEasingCurve::InCurve); // OutBounce<br> animation1->start();<br> int x2=bt2->pos().x();<br> int y2=bt2->pos().y();<br> QPropertyAnimation *animation2 = new QPropertyAnimation(bt2, "geometry");<br> animation2->setDuration(500);<br> animation2->setStartValue(QRect(bt2->pos().x(),bt2->pos().y(), bt2->width(), bt2->height()));<br> animation2->setEndValue(QRect(x1,y1, bt2->width(), bt2->height()));<br> animation2->setEasingCurve(QEasingCurve::InCurve); // OutBounce<br> animation2->start();<br> QPropertyAnimation *animation3 = new QPropertyAnimation(bt1, "geometry");<br> animation3->setDuration(500);<br> animation3->setStartValue(QRect(bt1->pos().x(),bt1->pos().y(), bt1->width(), bt1->height()));<br> animation3->setEndValue(QRect(x2,bt1->pos().y(), bt1->width(), bt1->height()));<br> animation3->setEasingCurve(QEasingCurve::InCurve); // OutBounce<br> animation3->start();<br> QPropertyAnimation *animation4 = new QPropertyAnimation(bt1, "geometry");<br> animation4->setDuration(500);<br> animation4->setStartValue(QRect(bt1->pos().x(),bt1->pos().y(), bt1->width(), bt1->height()));<br> animation4->setEndValue(QRect(x2,y2, bt1->width(), bt1->height()));<br> animation4->setEasingCurve(QEasingCurve::InCurve); // OutBounce<br> animation4->start();<br>} |
以上就是直播软件app开发,实现图片之间的交换动画, 更多内容欢迎关注之后的文章
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现