前两篇实现了Qt动画的缩放和移动,这次实现控件的透明渐变效果,如下面的动态图:
代码如下
头文件和前两篇博客的一样,这里只贴出cpp文件的代码
#include "mainwindow.h" #include "ui_mainwindow.h" #include#include#includeMainWindow::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-&