进度条功能demo

项目完整代码:MyTimer

界面

QT进度条

功能

  1. 点击start进度条开始刷新,pause暂停,stop停止并清空进度条;
  2. 点击button后修改使能状态。

实现

思路:定时器超时后,计数+1,更新progressBar的值。

主要代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
void MainWindow::init()
{
myTimer = new QTimer();
cnt = 0;
ui->progressBar->setValue(cnt);
// ...
connect(this->myTimer, SIGNAL(timeout()), this, SLOT(flushBar()));
}

void MainWindow::flushBar()
{
++cnt;
ui->progressBar->setValue(cnt);
if(cnt == 100)
{
QMessageBox::information(this, "Timer", "Done!");
on_stopButton_clicked();
}
}

进度条功能demo
https://ww1820.github.io/posts/f2585515/
作者
AWei
发布于
2023年6月2日
更新于
2023年6月2日
许可协议