0

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.

yo.alucino
  • 25
  • 6
  • 1
    How do you set or get the values? How do you check that the spinbox rounds the value? – Some programmer dude Mar 29 '22 at 06:51
  • Do you describe your story or do you have a question? – 273K Mar 29 '22 at 06:51
  • And if you want `0.0` to `0.99`, why not use a integer spinbox in the range of `0` to `99` and then divide by `100`? – Some programmer dude Mar 29 '22 at 06:51
  • @Someprogrammerdude I´m setting the value by simply calling the setvalue(), and similarly getting the value by calling getValue() which returns by definition double. It is rounding the values since I can set 1.1 but when setting 0.9 it will show 1.0. – yo.alucino Mar 29 '22 at 07:13
  • Please [edit] your question to show us a [mre] instead of describing your code. And please take some time to refresh [the help pages](http://stackoverflow.com/help), take the SO [tour], read [ask], as well as [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). – Some programmer dude Mar 29 '22 at 07:16
  • I can't reproduce the error. I have set the value of the `QDoubleSpinBox` to `0.9` and when I print the value (using `QDoubleSpinbox::value()`), I get `0.9` as expected, no rounding involved. It would make no sense if the widget were rounding its value. – Fareanor Mar 29 '22 at 08:49
  • Have you checked [`QDoubleSpinbox::minimum`](https://doc.qt.io/qt-5/qdoublespinbox.html#minimum-prop)? – m7913d Mar 29 '22 at 12:16

1 Answers1

0

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.