I think this is a wrong approach. Instead of fighting with the decimals, you should aim at converting the visual output of the spinbox to scientific notation and vice versa. Maybe you can leave the internal representation as it is now.
I think this is a wrong approach. Instead of fighting with the decimals, you should aim at converting the visual output of the spinbox to scientific notation and vice versa. Maybe you can leave the internal representation as it is now.
I have also thougth of that, but it is not possible. If I set the internal decimals to lets say 1000, then at the round function it will nevertheless be rounded to the maximum of decimals of a double. So at 1e-34 which is very likely more digits than a double without exponential can represent if will be rounded to 0. (Not tested, just my interpretation of the code)
Matthias
Even if you use the scientific notation internally this is represented as a double so the precision will be limited nevertheless. So here it doesn't matter.
I have now a working solution. However the code amount is about 600 LOC.
This widget is derived from QDoubleSpinBox. It uses a decimal value of 1000 (that is more decimal points than a double can handle) and implements a new decimal value for the presentation in scientific notation. The Validator is realised by setting the LineEdit to a QDoubleValidator::ScientificNotation. However the most important part is the reimplementation of textFromValue and valueFromText. This unfortunately requires to copy the whole validation code of QDoubleSpinBox, which can not be borrowed and represents the major part of the code.
Since I can not paste the whole code I put it online at:
http://www.matthiaspospiech.de/blog/...ific-notation/
Can this code be shrinked by keeping the functionality?
Bookmarks