QDoubleSpinBox->setValue() truncates floats/doubles
-
When I call setValue() on a QDoubleSpinBox, the value is truncated to an integer unless the difference between the current value and the new value is less than 1.
Example:
The "decimals" property of the spin box is set to 4.
spin box current value = 50
1st call to setValue(98.42) --> value changes to 98
2nd call to setValue(98.42) --> value changes to 98.42 -
When I call setValue() on a QDoubleSpinBox, the value is truncated to an integer unless the difference between the current value and the new value is less than 1.
Example:
The "decimals" property of the spin box is set to 4.
spin box current value = 50
1st call to setValue(98.42) --> value changes to 98
2nd call to setValue(98.42) --> value changes to 98.42Works fine for me with Qt6.7:
#include <QtWidgets> int main(int argc, char* argv[]) { QApplication app(argc, argv); QDoubleSpinBox dbl; dbl.setDecimals(4); dbl.show(); dbl.setValue(1.12); qDebug() << dbl.value(); QTimer::singleShot(1000, [&] { dbl.setValue(98.42); qDebug() << dbl.value(); }); QTimer::singleShot(2000, [&] { dbl.setValue(98.42); qDebug() << dbl.value(); }); return app.exec(); } -
Works fine for me with Qt6.7:
#include <QtWidgets> int main(int argc, char* argv[]) { QApplication app(argc, argv); QDoubleSpinBox dbl; dbl.setDecimals(4); dbl.show(); dbl.setValue(1.12); qDebug() << dbl.value(); QTimer::singleShot(1000, [&] { dbl.setValue(98.42); qDebug() << dbl.value(); }); QTimer::singleShot(2000, [&] { dbl.setValue(98.42); qDebug() << dbl.value(); }); return app.exec(); }@Christian-Ehrlicher It works okay for me with Qt 6.6 but not with Qt 5.15. It must have been fixed sometime in between.
-
@Christian-Ehrlicher It works okay for me with Qt 6.6 but not with Qt 5.15. It must have been fixed sometime in between.
@Christian Ehrlicher's code works as expected for me with Qt 5.15.2
-
@Christian-Ehrlicher It works okay for me with Qt 6.6 but not with Qt 5.15. It must have been fixed sometime in between.
@richferrara ... and for me on 5.15.3 on Linux
-
@richferrara ... and for me on 5.15.3 on Linux
@ChrisW67 I'm using 5.15.2 on Windows 10.
-
@ChrisW67 I'm using 5.15.2 on Windows 10.
@richferrara So did you try my testcase? What was printed on the console?
-
@richferrara So did you try my testcase? What was printed on the console?
@Christian-Ehrlicher I get the correct values (1.12, 98.42, 98.42). I don't understand why it's different in my Qt Creator application.