Qdoublespinbox does not allow values less than 1

271 Views Asked by At

Qdoublespinbox does not allow values less than 1, decimal values with precision grater than 1, values in positive range 0.00 - 0.99 (for example). There is no problem with setting it´s value to 1.1, 1.11, 1,04, but not 0.5 .... it is rounding up anyway to 1.

I have tried setting range to negative values with precision, setting explicitly the numbers of decimals and the minimum value of the widget, but all for nothing.

2

There are 2 best solutions below

1
kaloskagatos On

You can have a look at the Spin Boxes Example (accessible through QtCreator/Welcome/Examples or https://doc.qt.io/qt-5/qtwidgets-widgets-spinboxes-example.html).

You can have float or double precision rounding issues if you get your values from a calculation with not enough precision in memory.

You can also force the local to accept dot as decimal separator as you seem to mix comma and dot: add QLocale::setDefault(QLocale::C); at the beginning of your program. You can also create a custom double validator to accept both dot and comma by inheriting QDoubleValidator.

0
Thays On

I don't know if it's the same error that I've been finding, but I hope it could help people with the difficult that I had. I was using the QDoubleSpinBox and it was only allowing to put integer numbers, even though it was showing the comma... Only was possible to insert float numbers, when I changed the stepType (by default was "DefaultStepType"), when I put "AdaptativeDecimalStepType" I finnally was allowed to insert float numbers.