当前位置:网站首页>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);边栏推荐
- Build your own website (22)
- 手写ORM(对象关系映射)增删改查
- 【外刊】睡眠与减肥
- UE4 UI自适应屏幕
- 小鹏P7出事故,安全气囊未弹出,这正常吗?
- NC24325 [USACO 2012 Mar S]Flowerpot
- Rails 3 activerecord: sort by association count - rails 3 activerecord: order by count on Association
- Using rendertext() to output multiple lines of text with rendertext() in R shiny
- PHP wechat red packet grabbing algorithm
- Dahua cloud native load balancing article - the passenger flow of small restaurants has increased
猜你喜欢

Jatpack------LiveData

任务和特权级保护

Niuke: Dragon and dungeon games

Based on asp Net (used mobile phone sales management system) +asp Net+c # language +vs2010+ database can be used for course design and post design learning

Xiaopeng P7 had an accident and the airbag did not pop up. Is this normal?

Task and privilege level protection

SimpleITK使用——4. 奇怪的问题

分享 10 个 JS 闭包面试题(图解),进来看看你能答对多少

【板栗糖GIS】global mapper 如何通过dsm批量制作贴地等高线

SimpleITK使用——3. 常见操作
随机推荐
Niuke: Dragon and dungeon games
数学建模——图与网络模型及方法(一)
Simpleitk use - 4 Strange question
[LeetCode] 数组中的第K个最大元素【215】
Developers share | HLS and skillfully use Axi_ Customize the master bus interface instructions and improve the data bandwidth - area exchange speed
[leetcode] number of palindromes [9]
地方经销商玩转社区团购模式,百万运营分享
NC50965 Largest Rectangle in a Histogram
Simpleitk use - 3 Common operations
I admire that someone explained such an obscure subject as advanced mathematics so easily
E-commerce system microservice architecture
stop slave卡住--事务的事件没有复制完整
杰理之样机无触摸,拆机之后重新安装变正常【篇】
[autosar-dcm] - 4.3-how UDS $22 and $2e services read and write NVM data
Phpcms realizes the direct Alipay payment function of orders
Dynamic memory allocation (malloc calloc realloc free)
World Environment Day | Chow Tai Fook serves wholeheartedly to promote carbon reduction and environmental protection
Mathematical modeling -- graph and network models and methods (I)
NC24325 [USACO 2012 Mar S]Flowerpot
wait解决僵尸进程