当前位置:网站首页>QT implementation window gradually disappears qpropertyanimation+ progress bar
QT implementation window gradually disappears qpropertyanimation+ progress bar
2022-07-06 16:17:00 【Larry_ Yanan】
Meet a need , of FTP Upload , I plan to make a progress bar display , Finally, the gradient disappears such an effect . The first is to verify the possibility of gradual disappearance , So I found out QPropertyAnimation This thing .
One 、QPropertyAnimation Animation gradient disappears
The specific code is as follows :
QPropertyAnimation *animation = new QPropertyAnimation(this,"windowOpacity");
animation->setDuration(1000);
animation->setStartValue(1);
animation->setEndValue(0);
animation->start();
connect(animation,SIGNAL(finished()),this,SLOT(animation_close()));// Close after the effect is displayed
You can see , The code is very clean , In a few words, you can finish the effect of gradual disappearance .
1.new when ,windowOpacity That's the window / Opacity of components , It means that the next animation effect corresponds to the attribute of opacity
2.setDuration, Set duration ,1000 That's one second
3.setStartValue and setEndValue, The start value and end value are set respectively
4.connect, After the animation, jump to the custom slot function animation_close(), Exit procedure .
It should be noted that , in the light of windowOpacity Come on ,1 It's completely opaque , and 0 It's completely transparent , You can set it from 0.5 To 0, You can also set 0.3 To 0, But if it's set to 10 To 0, So in the next 1 In seconds , front 900 Milliseconds are unchanged , final 100 Will quickly walk from 1 To 0 The gradual disappearance process of .
For other types of attribute settings , for example geometry, His setValue It's not 1 and 0 了 , It is QRect Rectangle class , For example, the following paragraph , stay 10 In seconds from (0,0) To (250,250), By the way, I enlarged the size .
QPropertyAnimation *animation = new QPropertyAnimation(this, "geometry");
animation->setDuration(10000);
animation->setStartValue(QRect(0, 0, 30, 30));
animation->setEndValue(QRect(250, 250, 100, 100));
As for why setStartValue You can pass different parameters , Then you have to know QVariant This class .
also this, It means the object of transmission , The object of this animation .
In this case , You can treat an object , Set the corresponding position 、 Size 、 transparency , And the animation with specified frame rate .
It can be expected that , If you design a round or spherical widget , Trigger through a series of customized animations , You can even make a pretty good scroll animation ( Guessing )
Reference resources :
QT Animation frame
QT Attribute animation simulation QPropertyAnimation Use
Two 、QProgressBar Progress bar
This part QT Designer It's in there , Just use it directly
I think its default style is already very good-looking , Green , There is also a little flowing gradient effect .
If you are interested, you can search its style settings , There should be many kinds .
About the middle number , My side is on the right side by default , But the style sheet can be set as internal and intermediate
// Style sheets
QProgressBar#progressBar
{
text-align:center;
}
and
How to achieve the animation display of the progress bar , It's simple , Direct code
timer = new QTimer;
connect(timer,&QTimer::timeout, this, &MainWidget::timer_timeout);
ui->progressBar->setRange(0,100);
i= 0;
ui->progressBar->setValue(i);
timer->start(1000);
......
void MainWidget::timer_timeout()
{
i+=10;
ui->progressBar->setValue(i);
if(i==100)
{
timer->stop();
i=0;
on_closeButton_clicked();
}
}
ui->progressBar->setRange(0,100); Is the setting range ,ui->progressBar->setValue(i); Is to set the current value
Made a timer , Simulate the animation display of the progress bar , The effect is OK. .
边栏推荐
猜你喜欢
Analysis of protobuf format of real-time barrage and historical barrage at station B
树莓派4B安装opencv3.4.0
Codeforces Round #797 (Div. 3)无F
b站 实时弹幕和历史弹幕 Protobuf 格式解析
TCP's three handshakes and four waves
Codeforces Round #799 (Div. 4)A~H
628. Maximum product of three numbers
第 300 场周赛 - 力扣(LeetCode)
QT按钮点击切换QLineEdit焦点(含代码)
pytorch提取骨架(可微)
随机推荐
Li Kou - 298th weekly match
Classic application of stack -- bracket matching problem
Codeforces Round #798 (Div. 2)A~D
Generate random password / verification code
Nodejs crawler
图图的学习笔记-进程
Opencv learning log 29 -- gamma correction
(POJ - 3685) matrix (two sets and two parts)
TCP's three handshakes and four waves
frida hook so层、protobuf 数据解析
C basic grammar
C language must memorize code Encyclopedia
[teacher Gao UML software modeling foundation] collection of exercises and answers for level 20 cloud class
读取和保存zarr文件
Truck History
921. Minimum additions to make parentheses valid
Educational Codeforces Round 130 (Rated for Div. 2)A~C
QNetworkAccessManager实现ftp功能总结
[exercise-5] (UVA 839) not so mobile (balance)
QT实现窗口置顶、置顶状态切换、多窗口置顶优先关系