Qt动画(三):透明渐变
前两篇实现了Qt动画的缩放和移动,这次实现控件的透明渐变效果,如下面的动态图:代码如下
头文件和前两篇博客的一样,这里只贴出cpp文件的代码
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QGraphicsOpacityEffect>
#include <QPropertyAnimation>
#include <QSequentialAnimationGroup>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QGraphicsOpacityEffect *pButtonOpacity = new QGraphicsOpacityEffect(this);
pButtonOpacity->setOpacity(1);
ui->ToumingBlock->setGraphicsEffect(pButtonOpacity);
QPropertyAnimation *pOpacityAnimation1 = new QPropertyAnimation(pButtonOpacity, "opacity");
pOpacityAnimation1->setDuration(1000);
pOpacityAnimation1-&
文档来源:51CTO技术博客https://blog.51cto.com/u_12570763/3012388
页:
[1]