日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

qt 实现 以图片为中心 让它旋转_QT图片旋转动画

發布時間:2023/12/15 c/c++ 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 qt 实现 以图片为中心 让它旋转_QT图片旋转动画 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

自己開發了一個股票智能分析軟件,功能很強大,需要的點擊下面的鏈接獲取:

https://www.cnblogs.com/bclshuai/p/11380657.html

1.1 QT圖片旋轉動畫

1.1.1 應用場景說明

刪除圖片,圖片旋轉滾動到垃圾箱或者刪除按鈕時,需要有個滾動旋轉的動畫效果。需要用到QGraphicsView,QGraphicsScene,QGraphicsWidget,QLabel類,QGraphicsView類相當于黑色的框,和電視的外框類似,QGraphicsScene相當于動畫播放區域,下圖中的黑色框內部的白色區域,在這個白色區域內播放動畫。QGraphicsWidget相當于是動畫區域內的一個包裝類,將QLabel寫上文字或者通過setpixmap接口設置圖片后,添加到一個QGraphicsWidget,將QGraphicsWidget添加到QGraphicsScene,QGraphicsScene放到QGraphicsView,就可以實現旋轉圖片或者文字的動畫效果。

1.1.2 實現方法

(1) 定義旋轉角度屬性

頭文件定義

#ifndef ROTATIONVIEW_H

#define ROTATIONVIEW_H

#include <QGraphicsScene>

#include <QGraphicsView>

#include <QGraphicsWidget>

#include <QTextEdit>

#include <QPushButton>

#include <QGraphicsProxyWidget>

#include <QGraphicsLinearLayout>

class RotationView : public QGraphicsView

{

Q_OBJECT

Q_PROPERTY(int angle READ turnangle WRITE setturnangle)//自定義角度屬性

public:

RotationView(QWidget *parent);

~RotationView();

int turnangle() { return angle; };//get方法

void setturnangle(int angle);//set方法,動畫會通過這個函數輸入插值,使圖片轉動。

void startMove();

private:

QGraphicsView* view = NULL;

int angle=0;

QGraphicsWidget *pushButton = NULL;

};

#endif // ROTATIONVIEW_H

(2) 源文件實現

#include "RotationView.h"

#include<windows.h>

#include <QLabel>

#include <QPropertyAnimation>

#include <QRect>

RotationView::RotationView(QWidget *parent)

: QGraphicsView(parent)

{

//setWindowModality(Qt::NonModal);

setWindowFlags(Qt::FramelessWindowHint);

QGraphicsScene* scene = new QGraphicsScene(this);

// 創建部件,并關聯它們的信號和槽

QPushButton *button = new QPushButton("clear");

QLabel* plabel = new QLabel("turn me");

// button->resize(100, 100);

button->setGeometry(0, 0, 100, 100);

// 將部件添加到場景中

pushButton = scene->addWidget(plabel);

scene->addItem(pushButton);

view = new QGraphicsView(scene,this);

view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

pushButton->setParent(view);

pushButton->setPos(100, 100);

view->resize(200, 200);

//view->setStyleSheet("border:0px;");

view->show();

//view->setStyleSheet("border:0px;");

//setturnangle(90);

}

RotationView::~RotationView()

{

}

void RotationView::setturnangle(int angle)

{

QRectF r = pushButton->boundingRect();

//for (int i = 1; i <= 100; i++)

//{

pushButton->setTransform(QTransform()

.translate(r.width() / 2, r.height() / 2)

.rotate(angle - 360 * 1, Qt::ZAxis)

.translate(-r.width() / 2, -r.height() / 2));

view->update();

//}

}

void RotationView::startMove()

{

QPropertyAnimation * linelength = new QPropertyAnimation(pushButton, "geometry");

linelength->setDuration(3000);

linelength->setStartValue(QRect(5,5,50,50));

linelength->setEndValue(QRect(100, 100, 50, 50));

linelength->setEasingCurve(QEasingCurve::Linear);

linelength->start(QAbstractAnimation::DeleteWhenStopped);

}

(3) 定義對象設置屬性動畫

#include "qtrotation.h"

#include"RotationView.h"

#include <QPropertyAnimation>

QtRotation::QtRotation(QWidget *parent)

: QMainWindow(parent)

{

ui.setupUi(this);

RotationView* roview = new RotationView(this);

roview->setGeometry(50, 50, 200, 200);

QPropertyAnimation* rotation = newQPropertyAnimation(roview, "angle", this);

rotation->setDuration(300);

rotation->setStartValue(0);

rotation->setEndValue(720);

rotation->setLoopCount(20);

rotation->setEasingCurve(QEasingCurve::Linear);

connect(ui.pushRotation, &QPushButton::clicked, this, [=]() {

roview->startMove();

rotation->start();

});

}

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的qt 实现 以图片为中心 让它旋转_QT图片旋转动画的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。