Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. progressbar maximum and minumum problem
QtWS25 Last Chance

progressbar maximum and minumum problem

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
14 Posts 5 Posters 1.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    barisdemirbas
    wrote on 4 Jan 2022, 13:59 last edited by
    #1

    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.

    J 1 Reply Last reply 4 Jan 2022, 14:17
    0
    • B barisdemirbas
      4 Jan 2022, 13:59

      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.

      J Offline
      J Offline
      JonB
      wrote on 4 Jan 2022, 14:17 last edited by
      #2

      @barisdemirbas
      The bar will have a certain resolution. Try making it 0..100 and do steps of 1. Any difference? There is nothing special about a range of, say, 7200, everything gets divided when it calculates where to put its bar.

      B 1 Reply Last reply 4 Jan 2022, 15:09
      1
      • J JonB
        4 Jan 2022, 14:17

        @barisdemirbas
        The bar will have a certain resolution. Try making it 0..100 and do steps of 1. Any difference? There is nothing special about a range of, say, 7200, everything gets divided when it calculates where to put its bar.

        B Offline
        B Offline
        barisdemirbas
        wrote on 4 Jan 2022, 15:09 last edited by
        #3

        @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.

        J A 2 Replies Last reply 4 Jan 2022, 15:12
        0
        • B barisdemirbas
          4 Jan 2022, 15:09

          @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.

          J Offline
          J Offline
          JonB
          wrote on 4 Jan 2022, 15:12 last edited by JonB 1 Apr 2022, 15:17
          #4

          @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.]

          B 1 Reply Last reply 5 Jan 2022, 07:47
          2
          • B barisdemirbas
            4 Jan 2022, 15:09

            @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.

            A Offline
            A Offline
            artwaw
            wrote on 4 Jan 2022, 15:24 last edited by
            #5

            @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.

            For more information please re-read.

            Kind Regards,
            Artur

            1 Reply Last reply
            2
            • J JonB
              4 Jan 2022, 15:12

              @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.]

              B Offline
              B Offline
              barisdemirbas
              wrote on 5 Jan 2022, 07:47 last edited by
              #6

              @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.

              J 1 Reply Last reply 5 Jan 2022, 07:58
              0
              • B barisdemirbas
                5 Jan 2022, 07:47

                @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.

                J Offline
                J Offline
                JonB
                wrote on 5 Jan 2022, 07:58 last edited by JonB 1 May 2022, 08:00
                #7

                @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.

                B 1 Reply Last reply 5 Jan 2022, 08:12
                1
                • J JonB
                  5 Jan 2022, 07:58

                  @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.

                  B Offline
                  B Offline
                  barisdemirbas
                  wrote on 5 Jan 2022, 08:12 last edited by
                  #8

                  @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.

                  1 Reply Last reply
                  1
                  • R Offline
                    R Offline
                    Robert Loehning
                    wrote on 20 Jan 2022, 10:06 last edited by
                    #9

                    Please add the Qt version you to the bugreport.

                    B 1 Reply Last reply 3 Feb 2022, 11:43
                    0
                    • R Robert Loehning
                      20 Jan 2022, 10:06

                      Please add the Qt version you to the bugreport.

                      B Offline
                      B Offline
                      barisdemirbas
                      wrote on 3 Feb 2022, 11:43 last edited by
                      #10

                      @Robert-Loehning

                      Sorry for late reply. Issue was closed.

                      my qt version is "5.11.1"

                      Christian EhrlicherC 1 Reply Last reply 3 Feb 2022, 12:00
                      0
                      • B barisdemirbas
                        3 Feb 2022, 11:43

                        @Robert-Loehning

                        Sorry for late reply. Issue was closed.

                        my qt version is "5.11.1"

                        Christian EhrlicherC Online
                        Christian EhrlicherC Online
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on 3 Feb 2022, 12:00 last edited by
                        #11

                        @barisdemirbas Provide the information there. Also please add a minimal, compilable example to the bug report.

                        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                        Visit the Qt Academy at https://academy.qt.io/catalog

                        B 1 Reply Last reply 3 Feb 2022, 13:16
                        0
                        • Christian EhrlicherC Christian Ehrlicher
                          3 Feb 2022, 12:00

                          @barisdemirbas Provide the information there. Also please add a minimal, compilable example to the bug report.

                          B Offline
                          B Offline
                          barisdemirbas
                          wrote on 3 Feb 2022, 13:16 last edited by
                          #12

                          @Christian-Ehrlicher

                          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();
                          }
                          

                          / / / / /

                          pic_mainwindow.PNG

                          Best Regards

                          1 Reply Last reply
                          0
                          • Christian EhrlicherC Online
                            Christian EhrlicherC Online
                            Christian Ehrlicher
                            Lifetime Qt Champion
                            wrote on 3 Feb 2022, 13:20 last edited by
                            #13

                            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.

                            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                            Visit the Qt Academy at https://academy.qt.io/catalog

                            B 1 Reply Last reply 3 Feb 2022, 13:48
                            0
                            • Christian EhrlicherC Christian Ehrlicher
                              3 Feb 2022, 13:20

                              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.

                              B Offline
                              B Offline
                              barisdemirbas
                              wrote on 3 Feb 2022, 13:48 last edited by barisdemirbas 2 Mar 2022, 13:49
                              #14

                              @Christian-Ehrlicher

                              I added it to bugreport.

                              Thank you.

                              1 Reply Last reply
                              0

                              • Login

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • Users
                              • Groups
                              • Search
                              • Get Qt Extensions
                              • Unsolved