0

I need to create a QProgressBar where we can choose a range, the minimum and the maximum value.

Until now, I used a stylesheet for the same but the program is working(although not perfectly).

Stylesheet will allow me each time to change my background color and also bar color and each time I should add a small value because I'm using a qgradientline inside of stylesheet (not a good idea because of parsing time and also the progress bar is not generic)

image that shows what i want to do exactly

You can find the stylesheet xml below :

 setStyleSheet(QString("QProgressBar{background-color: %2; border: 2px solid %2; border-radius: 1px; margin: 0px; text-align: center;}"
                      "Q2ProgressBar:disabled{background-color: %3; border: 2px solid %3; border-radius: 1px; margin: 0px; text-align: center;}"
                  "QProgressBar::chunk{background-color: qlineargradient(x0: 0, x2: 1, stop : 0 %1, stop: %5 %1, stop: 0.%6 %4, stop: 1 %4); margin: 0px}"
                     ).arg(Q2UiColorsLocator::get().getDispText().name(),
                           Q2UiColorsLocator::get().getDispText().name(),
                           Q2UiColorsLocator::get().getDisabled().name(),
                           Q2UiColorsLocator::get().getDispBackground().name())
                          .arg(min+0.00001)
                          .arg(((min)+0.00002)));
eyllanesc
  • 235,170
  • 19
  • 170
  • 241

1 Answers1

0

From documentation about maximum field (https://doc.qt.io/qt-5/qprogressbar.html#maximum-prop)

This property holds the progress bar's maximum value

When setting this property, the minimum is adjusted if necessary to ensure that the range remains valid. If the current value falls outside the new range, the progress bar is reset with reset().

Access functions: int maximum() const
void setMaximum(int maximum)

So, have you tried with setMaximum? The same is with minimum. Access function is setMinimum

golobitch
  • 1,466
  • 3
  • 19
  • 38
  • setMaximum and set minimum allow you to set the range of barGraph but what i want is to set the maximum and the minimum value mean that if i set the minimum value the bargraph will not start from 0 as i show in the picture i put . :) – Omar Messari Jul 19 '19 at 06:50
  • So you want to set minimum value 10, and you want that the graph starts at 10? – golobitch Jul 19 '19 at 09:02
  • yes this is exactly what i want, the bar can have a range of x0,x1, but when i put setminimum(10) and setmaximum(30) i want to start my graph from 10 and end it a 30. the only solution i found now is to use qgradient with a stylesheet which is not a good idea (time of parsing adding a vilue to not have a gradiant color ..... and to much complicate if we have range of a very small or a very big numbers) so i'm trying to find another solution less complicate than that . – Omar Messari Jul 19 '19 at 09:11
  • Hm...honestly, I have no idea how to do this. However, you can use whole qprogress bar from 0 to 100 ... and ofcouse you should use %. so if in your case range is between 10 and 30 and value is 20 that is 50%, so that qprogressbar should be at 50%. Don't know how else I can help you. – golobitch Jul 19 '19 at 10:01
  • i got an idea i'll share it if it works, but i use QscrollBar, better than using a qgradientline. but should also pass by a stylesheet each time if i want to change the size of the scroller .... :(, but i think i'll won some speed and not to much complicate to write :D – Omar Messari Jul 19 '19 at 10:17