-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfadeinout.cpp
More file actions
64 lines (56 loc) · 1.58 KB
/
Copy pathfadeinout.cpp
File metadata and controls
64 lines (56 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "fadeinout.h"
//实现窗体的淡入和淡出效果
#include <QWidget>
fadeinout::fadeinout(QWidget* targetWidget,QObject *parent) :
QObject(parent)
{
this->target=targetWidget;
opacityEffect=new QGraphicsOpacityEffect();
target->setGraphicsEffect(opacityEffect);
opacityEffect->setOpacity(0.0);
//初始化定时器
timerOpacity=new QTimer(this);
connect(timerOpacity,SIGNAL(timeout()),this,SLOT(changeOpacity()));
isWorking=false;
}
//开始淡入淡出
void fadeinout::startFadeInOut(int effectType){
if(isWorking && effectType==this->effectType)
return;
this->effectType=effectType;
opaLevel=1.0;
if(effectType==FADEIN)
{
opaLevel=0.0;
}
timerOpacity->start(timerRate);
isWorking=true;
}
void fadeinout::changeOpacity(){
if(effectType==FADEIN)
{
if (opaLevel >= 1.0)
{
timerOpacity->stop();
isWorking=false;
return;
}
opacityEffect->setOpacity(opaLevel+=changeValue);
}
else
{
if (opaLevel <= 0.0)
{
timerOpacity->stop();
isWorking=false;
if(effectType==FADEOUT)
target->close();
else if(effectType==FADEOUT_HIDE)
target->hide();
else if(effectType==FADEOUT_EXIT)
exit(1);
return;
}
opacityEffect->setOpacity(opaLevel-=changeValue);
}
}