QProgressBar breaks with large values
-
Then use scaled values for your progress bar.
@Christian-Ehrlicher That was also one of my thoughts but I was hoping there would be a better way.
Is it possible to extends the QProgressBar class and override these methods and attributes? -
@Kekz said in QProgressBar breaks with large values:
Is it possible to extends the QProgressBar class and override these methods and attributes?
No and I don't see why it should be needed. If you need it derive from QProgressBar and do the scaling there but adding a
/100
or similar before passing the values isn't worth the trouble imo. -
@Kekz said in QProgressBar breaks with large values:
Is it possible to extends the QProgressBar class and override these methods and attributes?
No and I don't see why it should be needed. If you need it derive from QProgressBar and do the scaling there but adding a
/100
or similar before passing the values isn't worth the trouble imo.@Christian-Ehrlicher Deriving was what I meant, sry.
Then I will probably go that route and use 64-bit values, thanks for the help.
On second thought, that probably won't work. I will need to resort to scaling... -
@Christian-Ehrlicher That was also one of my thoughts but I was hoping there would be a better way.
Is it possible to extends the QProgressBar class and override these methods and attributes?@Kekz said in QProgressBar breaks with large values:
Is it possible to extends the QProgressBar class and override these methods and attributes?
Yes, it is.
The question could be: is it worth? rather than scale the values as @Christian-Ehrlicher suggested... -
@Christian-Ehrlicher Deriving was what I meant, sry.
Then I will probably go that route and use 64-bit values, thanks for the help.
On second thought, that probably won't work. I will need to resort to scaling...@Kekz
If it floats your boat, derive fromQProgressBar
and write your ownsetRange()
,setValue()
etc. new method overloads which accept asize_t
ordouble
or whatever. And that can do the division to do the "scaling" there, so your callers won't have to. -
@Kekz
If it floats your boat, derive fromQProgressBar
and write your ownsetRange()
,setValue()
etc. new method overloads which accept asize_t
ordouble
or whatever. And that can do the division to do the "scaling" there, so your callers won't have to. -
@Kekz Internally
ProgressBar will display the percentage of steps that have been completed when you later give it the current step value. The percentage is calculated by dividing the progress (value() - minimum()) / (maximum() - minimum())
So you can set value min max as 0,SCALE_MAX always irrespective file size.
ui->fileProgressBar->setRange(0,SCALE_MAX );void Controller::UpdateFileProgress( const size_t FileSize, const size_t value)
double ratio= static_cast<double>(value) / static_cast<double>(FileSize);
int scaledvalue =( ratio * SCALE_MAX ); -
@JonB
I was hoping to be able to also override the value, min and max attributes to force Qt to use 64-bit values, but that doesn't seem to work.
I'll have to scale the values down, it's an ugly solution but the only one that seems possible.@Kekz said in QProgressBar breaks with large values:
I was hoping to be able to also override the value, min and max attributes to force Qt to use 64-bit values, but that doesn't seem to work.
You cannot "override" variables, or the type of variables, in C++ (e.g. you cannot declare variables
virtual
).QProgressBar
usesint
s (32-bit) for these, and you cannot alter that.I'll have to scale the values down, it's an ugly solution but the only one that seems possible.
I do not see this as even vaguely "ugly".
QProgressBar
works off a range of possible values something like -2,000,000,000 to +2,000,000,000, which is more than enough to cover the visible "steps" available on the bar, and that's what you must supply it with for min/max/value. Scaling the number from, say afloat
to anint
seems fine to me, and you can add your own methods to yourQProgressBar
subclass to make this invisible to the outside world. -
@Kekz said in QProgressBar breaks with large values:
I was hoping to be able to also override the value, min and max attributes to force Qt to use 64-bit values, but that doesn't seem to work.
You cannot "override" variables, or the type of variables, in C++ (e.g. you cannot declare variables
virtual
).QProgressBar
usesint
s (32-bit) for these, and you cannot alter that.I'll have to scale the values down, it's an ugly solution but the only one that seems possible.
I do not see this as even vaguely "ugly".
QProgressBar
works off a range of possible values something like -2,000,000,000 to +2,000,000,000, which is more than enough to cover the visible "steps" available on the bar, and that's what you must supply it with for min/max/value. Scaling the number from, say afloat
to anint
seems fine to me, and you can add your own methods to yourQProgressBar
subclass to make this invisible to the outside world. -