Qt QWidget實(shí)現(xiàn)圖片旋轉(zhuǎn)動(dòng)畫
一、效果展示
二、源碼分享
本例程通過(guò)QGraphicsView實(shí)現(xiàn)svg格式圖片旋轉(zhuǎn)。
.hpp
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QGraphicsSvgItem> #include <QGraphicsScene> #include <QTimer> #include <QPropertyAnimation> QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } QT_END_NAMESPACE class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); private: Ui::MainWindow *ui; QGraphicsSvgItem *graphItem; QGraphicsScene *graphScene; }; #endif // MAINWINDOW_H
.cpp
#include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); this->graphScene = new QGraphicsScene(); this->ui->graphicsView->setScene(this->graphScene); this->graphItem = new QGraphicsSvgItem( ":/image/running.svg" ); this->graphItem->setScale(0.5); QRectF boundingRect = this->graphItem->boundingRect(); this->graphItem->setTransformOriginPoint(boundingRect.width() / 2, boundingRect.height() / 2); graphScene->addItem( this->graphItem ); this->graphItem->setRotation(45); // 創(chuàng)建一個(gè)QPropertyAnimation對(duì)象來(lái)控制旋轉(zhuǎn)屬性 QPropertyAnimation* rotationAnimation = new QPropertyAnimation(this->graphItem, "rotation"); // 設(shè)置動(dòng)畫的起始值和結(jié)束值 rotationAnimation->setStartValue(0); rotationAnimation->setEndValue(360); // 設(shè)置動(dòng)畫持續(xù)時(shí)間(以毫秒為單位) rotationAnimation->setDuration(3000); // 設(shè)置動(dòng)畫循環(huán)次數(shù)(-1表示無(wú)限循環(huán)) rotationAnimation->setLoopCount(-1); // 啟動(dòng)動(dòng)畫 rotationAnimation->start(); this->ui->graphicsView->installEventFilter(this); this->ui->graphicsView->centerOn(this->graphItem); } MainWindow::~MainWindow() { delete ui; }
以上就是Qt QWidget實(shí)現(xiàn)圖片旋轉(zhuǎn)動(dòng)畫的詳細(xì)內(nèi)容,更多關(guān)于Qt QWidget旋轉(zhuǎn)的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Matlab實(shí)現(xiàn)好看的配對(duì)箱線圖的繪制
配對(duì)箱線圖,常見(jiàn)于配對(duì)樣本的數(shù)據(jù)分析中,它除了能夠表現(xiàn)兩組的整體差異,還能夠清晰地呈現(xiàn)單個(gè)樣本的前后改變。本文將用Matlab實(shí)現(xiàn)配對(duì)箱線圖的繪制,需要的可以參考一下2022-08-08sublime text3搭建配置c語(yǔ)言編譯環(huán)境的詳細(xì)圖解教程(小白級(jí))
這篇文章主要介紹了sublime text3搭建配置c語(yǔ)言編譯環(huán)境,詳細(xì)圖解,小白教程,本文通過(guò)圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-01-01深入C/C++浮點(diǎn)數(shù)在內(nèi)存中的存儲(chǔ)方式詳解
本篇文章是對(duì)C/C++浮點(diǎn)數(shù)在內(nèi)存中的存儲(chǔ)方式進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05QT連接SQLServer數(shù)據(jù)庫(kù)的實(shí)現(xiàn)
要使用Qt連接SQL Server數(shù)據(jù)庫(kù),需要使用Qt提供的SQL模塊和SQL Server驅(qū)動(dòng)程序,具有一定的參考價(jià)值,感興趣的可以了解一下2023-09-09C++設(shè)計(jì)模式編程中的迭代器模式應(yīng)用解析
這篇文章主要介紹了C++設(shè)計(jì)模式編程中的迭代器模式應(yīng)用解析,迭代器模式注重對(duì)集合中元素的遍歷而不使其暴露,需要的朋友可以參考下2016-03-03C語(yǔ)言中if語(yǔ)句加大括號(hào)和不加大括號(hào)的區(qū)別介紹
這篇文章主要給大家介紹了關(guān)于C語(yǔ)言中if語(yǔ)句加大括號(hào)和不加大括號(hào)的區(qū)別,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-12-12