国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

QT動畫

2019-11-09 14:17:15
字體:
來源:轉載
供稿:網友
本代碼通過選擇文件導入圖片,然后用GraphicsView顯示,點擊開始動畫(漸隱,漸顯,變小,變大,旋轉)graphiCSSpeak.h
#ifndef GRAPHICSITEM_H#define GRAPHICSITEM_H#include <QGraphicsPixmapItem>#include <QGraphicsWidget>#include <QPainter>#include <QRect>#include <QPixmap>#include <QWidget>#include <QDebug>#include <QPRopertyAnimation>#include <QObject>#include <QWindow>class GraphicsItem : public QGraphicsWidget{    Q_OBJECT    Q_PROPERTY(QRectF geometry  READ geometry  WRITE setGeometry)    Q_PROPERTY(QPointF pos READ pos WRITE setPos)    Q_PROPERTY(qreal rotation READ rotation WRITE setRotation)    Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity)public:    GraphicsItem(QPixmap *pixmap);    QRectF boundingRect() const;    void paint(QPainter *painter,const QStyleOptionGraphicsItem *option,               QWidget *widget);private:    QRect my_rect;    QPixmap *my_Pixmap;};#endif // GRAPHICSITEM_HgraphicsSpeak.cpp
#include "graphicsitem.h"GraphicsItem::GraphicsItem(QPixmap *pixmap){    my_Pixmap = new QPixmap();    my_Pixmap = pixmap;}QRectF GraphicsItem::boundingRect() const{    return QRectF(-this->rect().width()/2,-this->rect().height()/2,this->rect().width(),this->rect().height());}void GraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){    painter->drawPixmap(boundingRect().toRect(),*my_Pixmap);}MainWindow.h
#ifndef MAINWINDOW_H#define MAINWINDOW_H#include <QMainWindow>#include <QGraphicsView>#include <QGraphicsScene>#include <QGraphicsWidget>#include <QPropertyAnimation>#include <QMouseEvent>#include <QFileDialog>#include <QMessageBox>#include "graphicsitem.h"namespace Ui {class MainWindow;}class MainWindow : public QMainWindow{    Q_OBJECTpublic:    explicit MainWindow(QWidget *parent = 0);    ~MainWindow();protected:    void mousePressEvent(QMouseEvent *event);private slots:    void on_pushButton_clicked();    void on_pushButton_2_clicked();private:    Ui::MainWindow *ui;    GraphicsItem *my_graphicsItem;    QPropertyAnimation *animation1;    QPropertyAnimation *animation2;    QPropertyAnimation *animation3;    QGraphicsScene *scene;    QPixmap pixmap;};#endif // MAINWINDOW_HMainWindiw.cpp
#include "mainwindow.h"#include "ui_mainwindow.h"MainWindow::MainWindow(QWidget *parent) :    QMainWindow(parent),    ui(new Ui::MainWindow){    ui->setupUi(this);    scene = new QGraphicsScene();    scene->setBackgroundBrush(Qt::black);    ui->graphicsView->setScene(scene);    ui->pushButton->setToolTip("選擇文件");    animation1 = new QPropertyAnimation();    animation2 = new QPropertyAnimation();    animation3 = new QPropertyAnimation();    animation1->setDuration(3000);    animation1->setStartValue(360);    animation1->setEndValue(0);    animation1->setLoopCount(-1);    animation3->setDuration(3000);    animation3->setStartValue(0);    animation3->setEndValue(1);    animation2->setDuration(5000);    animation2->setStartValue(QRect(0,0,97,46));    animation2->setKeyValueAt(0.5,QRect(0,0,97*4,46*4));    animation2->setEndValue(QRect(-550,-300,97,46));    connect(animation2,SIGNAL(finished()),animation1,SLOT(start()));}MainWindow::~MainWindow(){    delete ui;}void MainWindow::mousePressEvent(QMouseEvent *event){    if(animation2 != NULL&&animation2->state() != QAbstractAnimation::Running){        animation2->start();    }}void MainWindow::on_pushButton_clicked(){    QString path = QFileDialog::getOpenFileName(this, tr("Open Image"), ".", tr("Image Files( *.png)"));    if(!path.isEmpty())    {        ui->lineEdit->setText(path);    }    else{       QMessageBox::warning(NULL,"waring","請選擇圖片",QMessageBox::Yes|QMessageBox::No,QMessageBox::Yes);    }}void MainWindow::on_pushButton_2_clicked(){    pixmap.load(ui->lineEdit->text());    my_graphicsItem = new GraphicsItem(&pixmap);    scene->addItem(my_graphicsItem);    animation1->setTargetObject(my_graphicsItem);    animation2->setTargetObject(my_graphicsItem);    animation3->setTargetObject(my_graphicsItem);    animation1->setPropertyName("rotation");    animation2->setPropertyName("geometry");    animation3->setPropertyName("opacity");    animation3->start();}main.cpp
#include "mainwindow.h"#include <Qapplication>int main(int argc, char *argv[]){    QApplication a(argc, argv);    MainWindow w;    w.show();    return a.exec();}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 罗江县| 彭州市| 温州市| 宁城县| 双桥区| 洪泽县| 斗六市| 十堰市| 开化县| 河池市| 合阳县| 曲周县| 贡嘎县| 龙陵县| 东兴市| 潮州市| 沐川县| 灵璧县| 古浪县| 德州市| 绥芬河市| 濉溪县| 孝义市| 湛江市| 黑山县| 璧山县| 余庆县| 青海省| 肃宁县| 大同市| 融水| 龙井市| 南阳市| 左云县| 大石桥市| 梅河口市| 湟源县| 剑河县| 华坪县| 丰台区| 丰县|