当前位置: 首页 > wzjs >正文

谷歌网站建设推广方式有哪几种

谷歌网站建设,推广方式有哪几种,成都网络营销公司哪个好,一页网站首页图如何做《Qt动画编程实战:轻松实现头像旋转效果》 Qt 提供了丰富的动画框架,可以轻松实现各种平滑的动画效果。其中,旋转动画是一种常见的 UI 交互方式,广泛应用于加载指示器、按钮动画、场景变换等。本篇文章将详细介绍如何使用 Qt 实现…

《Qt动画编程实战:轻松实现头像旋转效果》

Qt 提供了丰富的动画框架,可以轻松实现各种平滑的动画效果。其中,旋转动画是一种常见的 UI 交互方式,广泛应用于加载指示器、按钮动画、场景变换等。本篇文章将详细介绍如何使用 Qt 实现旋转动画。
在这里插入图片描述

1、效果

在这里插入图片描述

2、具体实现

#ifndef ROTATINGIMAGE_H
#define ROTATINGIMAGE_H#include <QWidget>
#include <QLabel>
#include <QPropertyAnimation>class RotatingImage : public QWidget
{Q_OBJECTQ_PROPERTY(qreal rotation READ rotation WRITE setRotation)public:explicit RotatingImage(QWidget *parent = nullptr);qreal rotation() const { return m_rotation; }void setRotation(qreal rotation);public slots:void startRotation();void stopRotation();void pauseRotation();void resumeRotation();void setRotationDuration(int msecs);protected:void resizeEvent(QResizeEvent *event) override;private:void updatePixmap();QPixmap getScaledPixmap() const;private:QLabel *imageLabel;QPropertyAnimation *rotationAnimation;qreal m_rotation;QPixmap originalPixmap;QSize targetSize;
};#endif // ROTATINGIMAGE_H #include "rotatingimage.h"
#include <QPixmap>
#include <QTransform>
#include <QVBoxLayout>
#include <QResizeEvent>
#include <QPainter>
#include <QEasingCurve>RotatingImage::RotatingImage(QWidget *parent): QWidget(parent), m_rotation(0)
{// 创建布局QVBoxLayout *layout = new QVBoxLayout(this);layout->setContentsMargins(0, 0, 0, 0);// 创建标签并设置图片imageLabel = new QLabel(this);imageLabel->setFixedSize(QSize(200, 200));originalPixmap.load(":/images/test.png");// 设置目标大小targetSize = QSize(200, 200);  // 比Label小一点,留出边距// 初始化图片updatePixmap();imageLabel->setAlignment(Qt::AlignCenter);imageLabel->setStyleSheet("QLabel { border-radius: 100px; background: transparent; }");layout->addWidget(imageLabel, 0, Qt::AlignCenter);// 设置动画rotationAnimation = new QPropertyAnimation(this, "rotation", this);rotationAnimation->setStartValue(0.0);rotationAnimation->setEndValue(360.0);rotationAnimation->setDuration(5000);rotationAnimation->setLoopCount(-1);// 使用QEasingCurve使动画更流畅rotationAnimation->setEasingCurve(QEasingCurve::Linear);rotationAnimation->start();
}void RotatingImage::setRotation(qreal rotation)
{if (m_rotation != rotation) {m_rotation = rotation;updatePixmap();}
}void RotatingImage::updatePixmap()
{QPixmap scaledPix = getScaledPixmap();// 创建一个透明的目标图片,大小与Label相同QPixmap targetPixmap(imageLabel->size());targetPixmap.fill(Qt::transparent);// 在目标图片上绘制旋转后的图片QPainter painter(&targetPixmap);painter.setRenderHint(QPainter::Antialiasing);painter.setRenderHint(QPainter::SmoothPixmapTransform);// 计算中心点QPointF center = targetPixmap.rect().center();painter.translate(center);painter.rotate(m_rotation);painter.translate(-center);// 计算绘制位置使图片居中QPointF drawPos((targetPixmap.width() - scaledPix.width()) / 2.0,(targetPixmap.height() - scaledPix.height()) / 2.0);painter.drawPixmap(drawPos, scaledPix);painter.end();imageLabel->setPixmap(targetPixmap);
}QPixmap RotatingImage::getScaledPixmap() const
{return originalPixmap.scaled(targetSize,Qt::KeepAspectRatio,Qt::SmoothTransformation);
}void RotatingImage::resizeEvent(QResizeEvent *event)
{QWidget::resizeEvent(event);updatePixmap();
}void RotatingImage::startRotation()
{rotationAnimation->start();
}void RotatingImage::stopRotation()
{rotationAnimation->stop();
}void RotatingImage::pauseRotation()
{rotationAnimation->pause();
}void RotatingImage::resumeRotation()
{rotationAnimation->resume();
}void RotatingImage::setRotationDuration(int msecs)
{rotationAnimation->setDuration(msecs);
} #include <QApplication>
#include "rotatingimage.h"int main(int argc, char *argv[])
{QApplication app(argc, argv);RotatingImage *rotatingImage = new RotatingImage();rotatingImage->resize(400, 400);rotatingImage->show();return app.exec();
} 

3| 结语

Qt 的动画系统提供了丰富的 API,可以方便地实现旋转动画。本文介绍了 QPropertyAnimation 的基础用法、QWidgetQPainter 旋转方法,以及更高级的优化方案。希望这些内容能帮助你在实际开发中更好地使用 Qt 动画!
源码地址:https://github.com/MingYueRuYa/QtDemo

http://www.dtcms.com/wzjs/499641.html

相关文章:

  • 做网站需要几个岗位南京关键词优化服务
  • 文案推广发布网站大全免费信息发布平台网站
  • 源码网站免费新网站seo
  • 网站后台上传文章怎么做安装百度到桌面
  • 黑客软件资源网站搜索引擎推广试题
  • 如何做产品网站三只松鼠搜索引擎营销案例
  • python做网站视频教程搜狗指数官网
  • 云南制作网站的公司seo的概念是什么
  • 企业建站系统费用太原做网站推广的公司
  • 网站建设与制作山西优化公司
  • 网站空间数据库需要多大电商代运营公司十强
  • 做网站选大公司好还是小公司好网站搭建公司
  • 网站结构优化怎么做长沙百度推广优化排名
  • 深圳市建设注册执业资格中心网站网络舆情管理
  • 太仓网站建设哪家好软文推广多少钱
  • 自己做的创意的网站外链工具在线
  • 网站建设佰首选金手指十七谷歌优化怎么做
  • 响应式网站开发原理今天最火的新闻头条
  • 东营做网站排名网站提交入口
  • 网站建设依循的原则广州搜索排名优化
  • 用什么java软件做网站搜狗指数
  • 佛山市seo推广哪家好seo优化诊断工具
  • asp和php的建站区别制作网页的教程
  • 平面设计投稿平台深圳网站优化网站
  • wordpress 幻灯片代码在哪里设置seo排名优化代理
  • 江苏城工建设科技有限公司网站免费换友情链接
  • html中文网站模板下载营销官网
  • word文档怎么做网站跳转链接上海百度seo公司
  • 河南企业网站排名优化价格自助网站建设
  • 集团网站建设特色优化二十条