Qt实现图片渐进渐出效果

4 篇文章 0 订阅

http://blog.sina.com.cn/s/blog_75deeddd0100tu2s.html


图片渐进渐出效果
.h文件
#ifndef CHANGEPICTURE_H
#define CHANGEPICTURE_H
#include <QWidget>
#include <QtGui>
#include <QGraphicsEffect>
#include <QGraphicsView>
#include <QTimer>
class ChangePicture : public QGraphicsView
{
Q_OBJECT
public:
    ChangePicture(QStringList piclist,
                  QSize picSize,
                  QPoint picPoint,
                  int speed,
                  QWidget *parent = 0);
private:
    void setupScene();
    void createItems();
private slots:
    void setupEffect();
private:
    QStringList m_piclist;
    QSize m_picSize;
    QPoint m_picPoint;
    QTimer m_speed;
    qreal m_angle;
    QGraphicsScene m_scene;
    QGraphicsItem *m_dissolving;
    QTimer *m_speedTimer;
    QPixmap m_pixmap;
    int m_timerCounter;
    int m_picCount;
    int m_int_speed;
};
#endif // CHANGEPICTURE_H


.cpp文件
#include "changepicture.h"

ChangePicture::ChangePicture(QStringList piclist, QSize picSize, QPoint picPoint, int speed ,QWidget *parent) :
        QGraphicsView(parent),m_piclist(piclist),m_picSize(picSize),m_picPoint(picPoint),m_int_speed(speed),m_angle(0.0)
{
    this->setupScene();
    this->setupEffect();
    this->m_timerCounter = 0;
    this->m_picCount = 1;
    this->m_speedTimer = new QTimer(this);
    connect(this->m_speedTimer,SIGNAL(timeout()),this,SLOT(setupEffect()));
    this->m_speedTimer->start(m_int_speed);
}
void ChangePicture::setupScene()
{
    this->setScene(&this->m_scene);
    this->setRenderHint(QPainter::Antialiasing,true);
    this->setFrameStyle(QFrame::NoFrame);
    this->m_scene.setSceneRect(0,0,this->m_picSize.width(),this->m_picSize.height());
    this->createItems();
}
void ChangePicture::createItems()
{
    this->m_pixmap = QPixmap(m_piclist.at(0)).scaled(m_picSize);
    this->m_dissolving = this->m_scene.addPixmap(this->m_pixmap);
    this->m_dissolving->setPos(m_picPoint);
}
void ChangePicture::setupEffect()
{
    QGraphicsOpacityEffect *m_dissolvingEffect = new QGraphicsOpacityEffect(this);
    if(this->m_timerCounter != 100)
    {
        m_dissolvingEffect->setOpacity(this->m_timerCounter * 0.02);
        this->m_timerCounter++;
    }else
    {
        this->m_scene.clear();
        m_dissolvingEffect->setOpacity(m_angle);
        this->m_pixmap = QPixmap(m_piclist.at(m_picCount)).scaled(m_picSize);
        this->m_dissolving = this->m_scene.addPixmap(this->m_pixmap);
        this->m_dissolving->setPos(m_picPoint);
        this->m_timerCounter = 0;
        if(this->m_picCount >= this->m_piclist.size() - 1)
        {
            this->m_picCount = 0;
        }else
        {
            this->m_picCount++;
        }
    }
    this->m_dissolving->setGraphicsEffect(m_dissolvingEffect);
}


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值