1、
(1)界面出现
将下面这段代码放在界面的构造函数当中就行
[C++]
纯文本查看 复制代码
1
2
3
4
5
6
|
//界面动画,改变透明度的方式出现0 - 1渐变
QPropertyAnimation *animation =
new
QPropertyAnimation(
this
,
"windowOpacity"
);
animation->setDuration(1000);
animation->setStartValue(0);
animation->setEndValue(1);
animation->start();
|
既然是界面消失,应当是按下关闭按钮时界面消失,如下:
[C++]
纯文本查看 复制代码
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
|
//连接关闭按钮信号和槽
QObject::connect(close_button, SIGNAL(clicked()),
this
, SLOT(closeWidget()));
//槽函数如下,主要进行界面透明度的改变,完成之后连接槽close来调用closeEvent事件
bool
LoginDialog::closeWidget()
{
//界面动画,改变透明度的方式消失1 - 0渐变
QPropertyAnimation *animation =
new
QPropertyAnimation(
this
,
"windowOpacity"
);
animation->setDuration(1000);
animation->setStartValue(1);
animation->setEndValue(0);
animation->start();
connect(animation, SIGNAL(finished()),
this
, SLOT(close()));
return
true
;
}
void
LoginDialog::closeEvent(QCloseEvent *)
{
//退出系统
QApplication::quit();
}
|
界面消失:
[C++]
纯文本查看 复制代码
01
02
03
04
05
06
07
08
09
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
|
void
LoginDialog::closeEvent(QCloseEvent *)
{
for
(
int
i=0; i< 100000; i++)
{
if
(i<10000)
{
this
->setWindowOpacity(0.9);
}
else
if
(i<20000)
{
this
->setWindowOpacity(0.8);
}
else
if
(i<30000)
{
this
->setWindowOpacity(0.7);
}
else
if
(i<40000)
{
this
->setWindowOpacity(0.6);
}
else
if
(i<50000)
{
this
->setWindowOpacity(0.5);
}
else
if
(i<60000)
{
this
->setWindowOpacity(0.4);
}
else
if
(i<70000)
{
this
->setWindowOpacity(0.3);
}
else
if
(i<80000)
{
this
->setWindowOpacity(0.2);
}
else
if
(i<90000)
{
this
->setWindowOpacity(0.1);
}
else
{
this
->setWindowOpacity(0.0);
}
}
//进行窗口退出
QApplication::quit();
}
|