Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QProgressbar resets to -1



  • Hi,

    I was wondering why our progressbars in the dialogs never reached the maximum.
    The backend only increased the value by a delta, which was then handled in the dialog with something like:

    myBar->SetValue(myBar->value() + delta);
    

    As it turned out the Progressbar initializes with value = -1.
    Why is that?

    best,
    Megamouse


  • Qt Champions 2019

    @Megamouse Is it possible that at some point

    myBar->value() + delta
    

    were bigger than what you set using setRange()?


  • Moderators

    @jsulm actually from what I remember, set range does not change the current value.

    e.g
    value == 20 -> setRange(0,10) -> value still at 20

    I don't know why its done, but creating a QProgressBar or calling reset() on an existing one will set the current value to -1;

    I would assume that this is done, to allow the valueChanged() signal to be emitted when the value is set to 0?


  • Qt Champions 2019

    @J.Hilk I mean other way around: you set max to 10 and then setValue(11) - not sure what will happen.



  • @jsulm no the value wasn't exceeding the max. (but that was another issue later as you can read below)

    I think this whole implementation is simply weird.

    as J.Hilk said: the reset and init of any progressbar/dialog set the value to minimum-1 (apart from the QWinTaskBarProgress).

    Also apart from that... any increase/decrease above/below the min and max just returns without doing anything.....
    I think that is just wrong. the progressbar should always increase until max is reached. There is no logical explanation for this choice of implementation ...


Log in to reply