progressbar maximum and minumum problem
-
Hi all,
i have button and it decreases progressbar value. If progress bar begins at maximum value(7200) ,it passes %99 and jump to %98. directly. Same situation occurs when progress bar begins at minimum value (0) .But, if progress bar begins at 7199, i have no problem progress bar behaves properly.
Here is the code.
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "qdebug.h"MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
progressbarValue = 7200;
ui->progressBar->setRange(0,progressbarValue);
ui->progressBar->setValue(progressbarValue);}
MainWindow::~MainWindow()
{
delete ui;
}void MainWindow::on_increment_clicked()
{
progressbarValue -=5;
ui->progressBar->setValue(progressbarValue);
}/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
Thank you.
-
@barisdemirbas
The bar will have a certain resolution. Try making it0..100
and do steps of1
. Any difference? There is nothing special about a range of, say, 7200, everything gets divided when it calculates where to put its bar. -
@JonB thank you.
I tried before 0 to 100 and it works perfectly. But I want to simulate something for my project so i need to use 7200 as a size. If progress bar value begins from 7199 or 1 there is no problem(size is same - 7200). The problem happens when I assign the maximum or minimum value.
-
@barisdemirbas said in progressbar maximum and minumum problem:
for my project so i need to use 7200 as a size
No you don't. You want to use whatever happens to correspond to the "steps" of the progressbar. I don't think it has 7,200 steps.
Anyway, if it's as you say it must be down to a dividing/rounding issue. Pick figures which don't happen to produce this, e.g. just to try see what happens if you use 10,000 instead of 7,200, does it not "misbehave" as you claim it does now? Or always use 0..100 since that might be good for the progress steps, and do the multiplying/dividing/whatever on the value before you put it in. You presumably understand that you do not need to specify your data values for the bar's minimum/maximum, you can do the dividing into that range on your value instead of asking the progressbar to do it for you. [Using 7,200 as your maximum is just the same as using 100 but dividing your value by 72 before sending it to progressbar.]
-
@barisdemirbas @JonB is absolutely right, it is the progress bar's resolution issue. The progress get's rounded it during that 99% step is "lost". Either increase granularity/"resolution" of your values to produce more refined steps or otherwise transform your calculations.
I am very sure that if you try to calculate the percentage of the progress yourself (and put it to debug) using the problematic values you'd notice that it also "skips" the 99th percentile.
-
@JonB thank you.
/ / / / / / / / / / / / / / / / / 1 / / / / / / / / / / / / / / / / /
ui->setupUi(this);
progressbarValue = 10000;
ui->progressBar->setRange(0,10000);
ui->progressBar->setValue(progressbarValue);void MainWindow::on_decrement_clicked()
{
progressbarValue -=5;
ui->progressBar->setValue(progressbarValue);
qDebug()<<progressbarValue;
}/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
/ / / / / / / / / / / / / / / / / 2 / / / / / / / / / / / / / / / / /
ui->setupUi(this);
progressbarValue = 9995;
ui->progressBar->setRange(0,10000);
ui->progressBar->setValue(progressbarValue);void MainWindow::on_decrement_clicked()
{
progressbarValue -=5;
ui->progressBar->setValue(progressbarValue);
qDebug()<<progressbarValue;
}/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
Example 1: progress bar behaves not properly, jumps to %98 from %100 after 20 clicks, I see %99 only one time.(I still see 100% after 19 clicks.)
Example 2: progress bar works perfect, I see %98 after 20 click of button. I see %99 20 times.
Same size for both examples.(10000)Progress bar values are same (9925) for both examples. Size is also same(10000). But example 1 displays %100, examples 2 displays %99 for same progress bar value(9925).
I think maximum value assigning cause a problem.
-
@barisdemirbas
If your findings are correct (I don't intend to go test out) then I agree they are "surprising". After one decrement Example #1 should be in the same state as Example #2.- Divide all by 5 (range:
2000
, decrement-= 1
). Any different? - Divide by 100 (range
100
, decrement-= 1
). Any different?
Depending on your findings, either live with adjusting your range/value/decrement or report as Qt bug.
- Divide all by 5 (range:
-
@JonB thank you.
If range is 2000 and decrement -=1 same situation occurs and progress bar behaves not properly.
If range is 300 and decrement -=1 same situation occurs and progress bar behaves not properly.
If range is 100 and decrement -=1 progress bar works properly. (This situation there is one step from %100 to %99 , so we have no problem.)I will report this as Qt bug.
Best regards.
-
Please add the Qt version you to the bugreport.
-
-
@barisdemirbas Provide the information there. Also please add a minimal, compilable example to the bug report.
-
As I mentioned above, qprogress bar does not work properly when I assign the maximum or minimum value.
example : click "go to %100" button. After click decrease button you will see progress bar begins at maximum value(1000) ,it passes %99 and jump to %98. directly. Same situation occurs after click "go to %0". I can not add zip or any file to here so i share code below./ / / / /
#include "mainwindow.h" #include "ui_mainwindow.h" #include "QDebug" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); ui->progressBar->setRange(progressBarMin,progressBarMax); ui->progressBar->setValue(progressBarMin); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_pb_Reset_clicked() { progressBarValue = progressBarMin; ui->progressBar->setValue(progressBarValue); qDebug() << progressBarValue; } void MainWindow::on_pb_Set_clicked() { progressBarValue = progressBarMax; ui->progressBar->setValue(progressBarValue); qDebug() << progressBarValue; } void MainWindow::on_pb_decrease_clicked() { if(progressBarValue>progressBarMin) { progressBarValue -= 1; } ui->progressBar->setValue(progressBarValue); qDebug() << progressBarValue; } void MainWindow::on_pb_increase_clicked() { if(progressBarValue<progressBarMax) { progressBarValue += 1; } ui->progressBar->setValue(progressBarValue); qDebug() << progressBarValue; }
/ / / / /
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); private slots: void on_pb_Reset_clicked(); void on_pb_Set_clicked(); void on_pb_decrease_clicked(); void on_pb_increase_clicked(); private: Ui::MainWindow *ui; int progressBarValue = 0; const int progressBarMax = 1000; const int progressBarMin = 0; }; #endif // MAINWINDOW_H
/ / / / /
#include "mainwindow.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); }
/ / / / /
Best Regards
-
And as I said - please add it to your bugreport. Also please add the missing information (e.g. about this Qt version @Robert-Loehning asked you for). The forum is not a bug tracker.
And you're missing the ui file - better to not use a ui file at all but create the layout in the code. -