当前位置:网站首页>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);边栏推荐
- 小鹏P7出事故,安全气囊未弹出,这正常吗?
- Introduction and response to high concurrency
- 'when to use const char * and when to use const char []' - when to use const char * and when to use const char []
- Oracle-游标
- Jatpack------LiveData
- 数学建模——图与网络模型及方法(一)
- 性能优化----严苛模式
- 送给即将工作的自己
- 分享 10 个 JS 闭包面试题(图解),进来看看你能答对多少
- Jerry's modification does not require long press the boot function [chapter]
猜你喜欢

Addition, deletion, modification and query of handwritten ORM (object relationship mapping)
![[error record] the flutter reports an error (could not read script 'xxx\flutter\u tools\gradle\app\u plugin\u loader.gradle')](/img/02/67448df1817e8b34b654722df8ecd4.jpg)
[error record] the flutter reports an error (could not read script 'xxx\flutter\u tools\gradle\app\u plugin\u loader.gradle')

建立自己的网站(22)

NC50965 Largest Rectangle in a Histogram

大话云原生之负载均衡篇-小饭馆客流量变大了

附加:【登录信息存储】与【登录状态校验】;(包括:总结了到目前为止,有关【登录信息存储】与【登录状态校验】的所有内容;)

SimpleITK使用——4. 奇怪的問題
![NC24325 [USACO 2012 Mar S]Flowerpot](/img/cf/86acbcb524b3af0999ce887c877781.png)
NC24325 [USACO 2012 Mar S]Flowerpot

悬镜安全在RSAC2022上斩获Global InfoSec Awards四项大奖

Phpcms realizes the direct Alipay payment function of orders
随机推荐
Film and television excerpts
Graphic view frame
Go 4 modes Singleton
uniapp微信登录返显用户名和头像
Performance optimization - rigorous mode
[leetcode] there are duplicate elements [217]
用sentinel熔断比例阈值改不了,设置慢调用比例没效果
Array advanced improvement
Notes on key vocabulary of the original English book biography of jobs (IX) [chapter seven]
php实现根据输入的年龄查询出生日期符合的数据
[chestnut sugar GIS] ArcMap - how to batch modify the font, color, size, etc. of annotation elements
Golang interview finishing three resumes how to write
【板栗糖GIS】global mapper 如何通过dsm批量制作贴地等高线
《乔布斯传》英文原著重点词汇笔记(十)【 chapter eight】
NC24325 [USACO 2012 Mar S]Flowerpot
Simpleitk use - 4 Strange question
[micro service sentinel] rewrite Sentinel's interface blockexceptionhandler
[LeetCode] 反转字符串【344】
JS syntax ES6, ES7, es8, es9, ES10, es11, ES12 new features (Abstract)
杰理之如何测试按键的误触率【篇】