当前位置:网站首页>Qt QProgressBar详解
Qt QProgressBar详解
2022-07-02 22:09:00 【Mr.codeee】
1.QProgressBar简述
QProgressBar提供了一个水平或垂直的进度条,可以使用setMinimum()和setMaximum指定最小和最大步数。当前的步数是用setValue()设置的。进度条可以用reset()重绕到开头。
2.常用方法
void setMaximum(int maximum) | 设置最大值 |
void setMinimum(int minimum) | 设置最小值 |
void setRange(int minimum, int maximum) | 设置范围,最大、最小值 |
void setValue(int value) | 设置当前值 |
void reset() | 重置 |
void setOrientation(Qt::Orientation) | 设置方向,垂直,水平 |
void setAlignment(Qt::Alignment alignment) | 设置对齐方式,居中,左、右 |
void setTextVisible(bool visible) | 设置进度条文本是否显示 |
void setInvertedAppearance(bool invert) | 设置正、反 |
void setFormat(const QString &format) | 设置文本显示格式 |
3.示例,比较进度条
p1设置如下,正常设置。
ui->progressBar1->setMinimum(0);
ui->progressBar1->setMaximum(100);
ui->progressBar1->setValue(50);
ui->progressBar1->setOrientation(Qt::Horizontal);
p2设置如下,设置了文字对齐方式,进度条方向等。
ui->progressBar2->setMinimum(0);
ui->progressBar2->setMaximum(100);
ui->progressBar2->setValue(50);
ui->progressBar2->setOrientation(Qt::Horizontal);
ui->progressBar2->setInvertedAppearance(true);//设置反方向
ui->progressBar2->setFormat("%v");
ui->progressBar2->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); // 对齐方式
setFormat(),有如下几种方式
%p% | 百分比,这是默认的显示方式 |
%v | 当前进度 |
%m | 总步数 |
也可以直接设置显示的值,如下图所示,显示小数。
ui->progressBar1->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); // 对齐方式
ui->progressBar1->setFormat(QString("cur progress value:%1%").arg(QString::number(50.43, 'f', 2)));
p3设置如下,繁忙进度显示。
只需设置最大值、最小值为0就行了。
ui->progressBar3->setMinimum(0);
ui->progressBar3->setMaximum(0);
4.设置样式表
这里简单设置一下样式表。效果如下,仅供参考。
QString s1 = "QProgressBar {\
border: 2px solid grey;\
border-radius: 5px;\
text-align: center;\
color:#ff0000;\
}";
QString s2 = "QProgressBar::chunk {\
background-color: #05B8CC;\
width: 20px;\
margin: 0.5px;\
}";
调用
ui->progressBar1->setStyleSheet(s1+s2);
边栏推荐
猜你喜欢
Simpleitk use - 4 Strange question
[LeetCode] 多数元素【169】
数据分析学习记录(二)---响应曲面法及Design-Expert的简单使用
【ODX Studio编辑PDX】-0.1-如何快速查看各Variant变体间的支持的诊断信息差异(服务,Sub-Function...)
PMP项目整合管理
图形视图框架
【板栗糖GIS】arcmap—为什么使用自定义捕捉的时候,经典捕捉的勾要去掉呢?
数学建模——图与网络模型及方法(一)
Hanging mirror security won four global infosec awards on rsac2022
Build your own website (22)
随机推荐
高并发介绍及应对
电商系统微服务架构
Performance optimization - rigorous mode
佩服,竟然有人把高等数学这么晦涩难懂的科目,讲解得如此通俗易懂
Socket socket c/s end process
wait解决僵尸进程
杰理之、产线装配环节【篇】
uniapp微信登录返显用户名和头像
世界环境日 | 周大福用心服务推动减碳环保
[ODX studio edit PDX] -0.1- how to quickly view the differences in supported diagnostic information between variant variants (service, sub function...)
Kubernetes uses the host name to allocate the pod on the specified node
杰理之内置短按再长按,不管长按多长时间都是短按【篇】
Oracle-PL/SQL编程
SimpleITK使用——3. 常见操作
Simpleitk use - 4 Strange question
How can I use knockout's $parent/$root pseudovariables from inside a . computed() observable?
kubernetes 使用主机名将 pod 分配在指定节点上
Xiaopeng P7 had an accident and the airbag did not pop up. Is this normal?
全面解析分享购商业模式逻辑?分享购是如何赋能企业
go 多线程数据搜索