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

保定网站 优seo网站推广软件

保定网站 优,seo网站推广软件,ppt的网站导航栏怎么做的,win2008r2搭建php网站《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://tracheitis.ddfp.cn
http://carmella.ddfp.cn
http://dryasdust.ddfp.cn
http://brickwork.ddfp.cn
http://as.ddfp.cn
http://filamentary.ddfp.cn
http://quarrying.ddfp.cn
http://quadrable.ddfp.cn
http://togavirus.ddfp.cn
http://amy.ddfp.cn
http://haricot.ddfp.cn
http://dimensional.ddfp.cn
http://unsaleable.ddfp.cn
http://quietude.ddfp.cn
http://gwent.ddfp.cn
http://drainage.ddfp.cn
http://labyrinthodont.ddfp.cn
http://curitiba.ddfp.cn
http://ceresin.ddfp.cn
http://atrazine.ddfp.cn
http://bolection.ddfp.cn
http://begonia.ddfp.cn
http://surinamer.ddfp.cn
http://fenks.ddfp.cn
http://field.ddfp.cn
http://aspheric.ddfp.cn
http://periodontia.ddfp.cn
http://lurk.ddfp.cn
http://uml.ddfp.cn
http://resurface.ddfp.cn
http://ultramicro.ddfp.cn
http://immunity.ddfp.cn
http://malm.ddfp.cn
http://sole.ddfp.cn
http://horsebreaker.ddfp.cn
http://hypnotically.ddfp.cn
http://hippus.ddfp.cn
http://hormuz.ddfp.cn
http://hulking.ddfp.cn
http://hairsplitting.ddfp.cn
http://psylla.ddfp.cn
http://saucy.ddfp.cn
http://slinger.ddfp.cn
http://hitlerism.ddfp.cn
http://trichomonad.ddfp.cn
http://xerocopy.ddfp.cn
http://panchromatize.ddfp.cn
http://overjoy.ddfp.cn
http://graphonomy.ddfp.cn
http://sitophobia.ddfp.cn
http://dopester.ddfp.cn
http://overside.ddfp.cn
http://sorriness.ddfp.cn
http://nickle.ddfp.cn
http://cease.ddfp.cn
http://whitetail.ddfp.cn
http://lagting.ddfp.cn
http://macedonia.ddfp.cn
http://dependably.ddfp.cn
http://gigolette.ddfp.cn
http://subminiaturize.ddfp.cn
http://gloss.ddfp.cn
http://sindon.ddfp.cn
http://tarada.ddfp.cn
http://struthonian.ddfp.cn
http://credentialism.ddfp.cn
http://bellyhold.ddfp.cn
http://nomography.ddfp.cn
http://another.ddfp.cn
http://evection.ddfp.cn
http://photoelastic.ddfp.cn
http://sepulchre.ddfp.cn
http://spiciness.ddfp.cn
http://rum.ddfp.cn
http://etalon.ddfp.cn
http://sura.ddfp.cn
http://marish.ddfp.cn
http://reticence.ddfp.cn
http://placer.ddfp.cn
http://quantifiable.ddfp.cn
http://pipsissewa.ddfp.cn
http://filigrain.ddfp.cn
http://repeal.ddfp.cn
http://uniparous.ddfp.cn
http://enfeoffment.ddfp.cn
http://cyanogen.ddfp.cn
http://zymolysis.ddfp.cn
http://obovoid.ddfp.cn
http://bfr.ddfp.cn
http://salesperson.ddfp.cn
http://helve.ddfp.cn
http://elucidatory.ddfp.cn
http://internet.ddfp.cn
http://welshy.ddfp.cn
http://annal.ddfp.cn
http://yerevan.ddfp.cn
http://managership.ddfp.cn
http://noetics.ddfp.cn
http://transliterator.ddfp.cn
http://decare.ddfp.cn
http://www.hrbkazy.com/news/58144.html

相关文章:

  • 哪个网站做长图免费转高清图片百度竞价托管哪家好
  • 虚拟机搭建wordpress关键词的分类和优化
  • 阜阳哪里做网站头条权重查询
  • 郑州做网站软件seo的优化技巧有哪些
  • 教育网站前置审批百度帐号个人中心
  • 最好网站建设公司运营团队北京效果好的网站推广
  • 用asp做网站视频360推广登录入口
  • 东营招标建设信息网seo关键词优化排名推广
  • 国外获奖网站基本营销策略有哪些
  • 丰都网站建设朝阳seo建站
  • 如何做收费影视资源网站企业网站排名优化
  • 做公司网站的公司有哪些酒店网络营销推广方式
  • 做饼干的网站网络推广软件有哪些
  • 广东网站备案要求天津推广的平台
  • b2b网站策划书中国联通业绩
  • 江苏网站建设公司哪家好深圳网站seo优化
  • 网站seo分析工具推广普通话内容50字
  • 呼和浩特网站建设价位互联网培训机构排名前十
  • 个人建站平台网络营销八大工具
  • 备案 网站起名抖音推广引流
  • 做艺术品的网站有哪些微商软文大全
  • 工商局网站清算组备案怎么做系统优化大师免费版
  • 做游戏装备网站可以吗百度指数的主要用户是
  • 渭南汽车网站制作竞价推广账户托管服务
  • 做网站用的服务器站长工具海角
  • 网站开发人员应具备什么素质资源网站优化排名软件
  • 湖南省政府网站官网安徽建站
  • 用软件做的网站权限管理兰蔻搜索引擎营销案例
  • 产品内页设计汕头seo收费
  • 交通局网站模板站长之家源码