[SOLVED] QDoubleSpinBox - hidding decimal when the number is Integer?
-
I have this QDoubleSpinBox: "https://www.dropbox.com/s/l8xm7h0fb5b8rr9/SpinBoxQDouble.png?dl=0":https://www.dropbox.com/s/l8xm7h0fb5b8rr9/SpinBoxQDouble.png?dl=0
When I want to edit the QDoubleSpinBox, I set the value inside and would like to hide the decimal if the number is Integer*
*(number - ((int)number) = 0.0)I tried subclassing QDoubleSpinBox and re-implement textFromValue and creating the QString there without the decimal, but the function never seem to be called? (still show the decimals)
Is there an easier way that i'm missing?
Thanks!
-
Do you have some code?
How do you "hide" the decimals?
Try catching the signal valueChanged(), check whether it is an integer or not and then use setDecimals(0)...[EDIT]
Problem is, that neighter valueChanged(double) nor valueChanged(const QString &) fire when comma is pressed, so maybe you should catch the keyPressEvent and check spinbox text via text().count(",") --> if greater then zero, set decimals to two, otherwise to zero... maybe that works for you... -
Hi,
Can you show your implementation ?
-
Hey guys thanks for the reply,
Finally I went back to using a standard QDoubleSpinBox for now. The reason to hide the decimals is purely aesthetic so it can wait..The code was something like :
@QString myDoubleSpinBox::textFromValue ( double value ) {
if(value - ((int)value) != 0)
return QString::number(value, 'f', 2);
else
return QString::number((int)value));
}@And the decimals in the QDoubleSpinBox use "dot" (.) not commas here it seems, maybe it use the locale
-
Indeed comma vs point comes from the locale
-
One thing to consider would be to have an option on the QDoubleSpinBox (decimal hidden) so that if the user type "45" it doesn't change to "45.00" once finish editing, let the SpinBox accept double but only show the decimals if the decimal symbol have been pressed (, or . depending on the locale).
Have a great day!
-
You can try making a feature request (or see if such one was already made)
-
Alright will check to do that.
I have checked on : https://qt-project.org/search/tag/feature~request
but not sure how the feature request works, can't seem to find where to create a new request.
Sorry for my noobiness ;) -
The "bug report system":http://bugreports.qt-project.org is the right place. Just select the feature request option rather than bug. But first, take the time to check whether there was already something about it