Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. progressbar level indicator
Qt 6.11 is out! See what's new in the release blog

progressbar level indicator

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 985 Views 1 Watching
  • 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.
  • V Offline
    V Offline
    viniltc
    wrote on last edited by
    #1

    Hi All,

    I've progress bar to display the instantaneous value of real-time sensor.

    the range for the QProgressBar is set as

    ui->progressBar->setRange(0, 0.5*100); // to make range integer
    
    ui->progressBar->setValue(sensor_read*100);
    

    It is working ok.
    Now I need to set a "threshold" value using a doubleSpinBox , as shown below:

    enter image description here

    The position of the dotted line (which is a QLabel) is the threshold that can be set using a doubleSpinBox.

    My requirement is to change the height of the dotted line with respect to the threshold value.

    the top and bottom y coordinates of the QProgressBar is 250 and 450

    How do I get proportional y coordinate for the QLabel (dotted line) when I set a threshold value using doubleSpinBox?

    JonBJ J.HilkJ 2 Replies Last reply
    0
    • V viniltc

      Hi All,

      I've progress bar to display the instantaneous value of real-time sensor.

      the range for the QProgressBar is set as

      ui->progressBar->setRange(0, 0.5*100); // to make range integer
      
      ui->progressBar->setValue(sensor_read*100);
      

      It is working ok.
      Now I need to set a "threshold" value using a doubleSpinBox , as shown below:

      enter image description here

      The position of the dotted line (which is a QLabel) is the threshold that can be set using a doubleSpinBox.

      My requirement is to change the height of the dotted line with respect to the threshold value.

      the top and bottom y coordinates of the QProgressBar is 250 and 450

      How do I get proportional y coordinate for the QLabel (dotted line) when I set a threshold value using doubleSpinBox?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @viniltc
      Basic math? 250 + (450 - 250) * percentage? top + height * percentage? Or pretty similar?

      1 Reply Last reply
      0
      • V viniltc

        Hi All,

        I've progress bar to display the instantaneous value of real-time sensor.

        the range for the QProgressBar is set as

        ui->progressBar->setRange(0, 0.5*100); // to make range integer
        
        ui->progressBar->setValue(sensor_read*100);
        

        It is working ok.
        Now I need to set a "threshold" value using a doubleSpinBox , as shown below:

        enter image description here

        The position of the dotted line (which is a QLabel) is the threshold that can be set using a doubleSpinBox.

        My requirement is to change the height of the dotted line with respect to the threshold value.

        the top and bottom y coordinates of the QProgressBar is 250 and 450

        How do I get proportional y coordinate for the QLabel (dotted line) when I set a threshold value using doubleSpinBox?

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #3

        @viniltc the easiest way is probably to place a Vertical Layout onto of your progress bar and then manipulate the stretch values according to the spin box value

        like in this example:

        int main (int argc, char *argv[])
        {
            QApplication a(argc, argv);
        
        
            QWidget w;
            w.resize (200, 400);
            QHBoxLayout *hLay(new QHBoxLayout(&w));
        
            QProgressBar pBar;
            pBar.setOrientation(Qt::Vertical);
            pBar.setMinimumWidth(50);
            QSpinBox sBox;
            sBox.setRange(0,100);
            hLay->addWidget(&pBar);
            hLay->addWidget(&sBox);
        
            QVBoxLayout *vLay(new QVBoxLayout(&pBar));
            vLay->addSpacerItem(new QSpacerItem(0,0, QSizePolicy::Expanding, QSizePolicy::Expanding));
            vLay->addWidget(new QLabel ("________"));
            vLay->addSpacerItem(new QSpacerItem(0,0, QSizePolicy::Expanding, QSizePolicy::Expanding));
        
            QObject::connect(&sBox, QOverload<int>::of(&QSpinBox::valueChanged), &pBar, [vLay](int value)->void{
                vLay->setStretch(0, 100 - value);
                vLay->setStretch(1,1);
                vLay->setStretch(2, value);
            });
        
            sBox.setValue(20);
        
            w.show();
            return  a.exec();
        }
        

        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply
        1
        • V Offline
          V Offline
          viniltc
          wrote on last edited by
          #4

          @J-Hilk and @JonB Thanks a lot for your feedback.

          @JonB said in progressbar level indicator:

          Basic math? 250 + (450 - 250) * percentage? top + height * percentage? Or pretty similar?

          Could you explain what you mean by percentage here?

          I 'm trying to do something like this (changing the y coordinate of label):

           double value = 450-(ui->doubleSpinBox->value()*100); // where 450 is the bottom of progress bar, here value is not proportional to the progressbar limit
           ui->label->setGeometry(140,value,81,16);
          
          

          But I'm a bit stuck to find a range for value also to make sure it chnage in proporation to the QProgressbar. Any suggestions?

          JonBJ 1 Reply Last reply
          0
          • V viniltc

            @J-Hilk and @JonB Thanks a lot for your feedback.

            @JonB said in progressbar level indicator:

            Basic math? 250 + (450 - 250) * percentage? top + height * percentage? Or pretty similar?

            Could you explain what you mean by percentage here?

            I 'm trying to do something like this (changing the y coordinate of label):

             double value = 450-(ui->doubleSpinBox->value()*100); // where 450 is the bottom of progress bar, here value is not proportional to the progressbar limit
             ui->label->setGeometry(140,value,81,16);
            
            

            But I'm a bit stuck to find a range for value also to make sure it chnage in proporation to the QProgressbar. Any suggestions?

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @viniltc
            You have some minimum value for the bar, say lo. You have some maximum value, say hi. And a value, say value. Doesn't matter whether those are integers, floats or whatever. So by "percentage" (actually fraction) I mean:

            (value - lo) / (hi - lo)
            

            You want your y coordinate to be miny + (maxy - miny) * percentage.

            1 Reply Last reply
            1

            • Login

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