add useless animation

This commit is contained in:
Gary Wang 2019-10-03 11:00:28 +08:00
parent 096ff5170b
commit 0ff1e80132
2 changed files with 36 additions and 0 deletions

View File

@ -11,6 +11,7 @@
#include <QApplication>
#include <QStyle>
#include <QScreen>
#include <QGraphicsOpacityEffect>
#ifdef _WIN32
#include <windows.h>
@ -73,6 +74,13 @@ MainWindow::MainWindow(QWidget *parent) :
m_graphicsView->checkAndDoFitInView();
});
m_opacityEffect = new QGraphicsOpacityEffect(m_bottomButtonGroup);
m_bottomButtonGroup->setGraphicsEffect(m_opacityEffect);
m_btnGrpAnimation = new QPropertyAnimation(m_opacityEffect, "opacity");
m_btnGrpAnimation->setDuration(300);
m_opacityEffect->setOpacity(0);
centerWindow();
}
@ -115,6 +123,26 @@ void MainWindow::showEvent(QShowEvent *event)
return QMainWindow::showEvent(event);
}
void MainWindow::enterEvent(QEvent *event)
{
m_btnGrpAnimation->stop();
m_btnGrpAnimation->setStartValue(m_opacityEffect->opacity());
m_btnGrpAnimation->setEndValue(1);
m_btnGrpAnimation->start();
return QMainWindow::enterEvent(event);
}
void MainWindow::leaveEvent(QEvent *event)
{
m_btnGrpAnimation->stop();
m_btnGrpAnimation->setStartValue(m_opacityEffect->opacity());
m_btnGrpAnimation->setEndValue(0);
m_btnGrpAnimation->start();
return QMainWindow::leaveEvent(event);
}
void MainWindow::mousePressEvent(QMouseEvent *event)
{
if (event->buttons() & Qt::LeftButton) {

View File

@ -6,6 +6,10 @@
#include <QPropertyAnimation>
#include <QPushButton>
QT_BEGIN_NAMESPACE
class QGraphicsOpacityEffect;
QT_END_NAMESPACE
class GraphicsView;
class BottomButtonGroup;
class MainWindow : public QMainWindow
@ -21,6 +25,8 @@ public:
protected slots:
void showEvent(QShowEvent *event) override;
void enterEvent(QEvent *event) override;
void leaveEvent(QEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
@ -35,6 +41,8 @@ protected slots:
private:
QPoint m_oldMousePos;
QGraphicsOpacityEffect *m_opacityEffect;
QPropertyAnimation *m_btnGrpAnimation;
QPropertyAnimation *m_fadeOutAnimation;
QPropertyAnimation *m_floatUpAnimation;
QParallelAnimationGroup *m_exitAnimationGroup;