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 barisdemirbas

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

    artwawA Offline
    artwawA Offline
    artwaw
    wrote on 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
    • JonBJ JonB

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

      JonBJ 1 Reply Last reply
      0
      • B barisdemirbas

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

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #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
        1
        • JonBJ JonB

          @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 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 last edited by
            #9

            Please add the Qt version you to the bugreport.

            B 1 Reply Last reply
            0
            • R Robert Loehning

              Please add the Qt version you to the bugreport.

              B Offline
              B Offline
              barisdemirbas
              wrote on 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
              0
              • B barisdemirbas

                @Robert-Loehning

                Sorry for late reply. Issue was closed.

                my qt version is "5.11.1"

                Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on 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
                0
                • Christian EhrlicherC Christian Ehrlicher

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

                  B Offline
                  B Offline
                  barisdemirbas
                  wrote on 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 Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on 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
                    0
                    • Christian EhrlicherC Christian Ehrlicher

                      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 last edited by barisdemirbas
                      #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