nav-left cat-right
cat-right
Home » Blog » 2009 » Januar

Qt SpinBox Widget with Scientific Notation...

QScienceSpinBox

Since I started using Qt over a year ago I have been asking and looking for a Qt widget that can handle numbers in a scientific notation. Unfortunately Qt Software does not offer such a solution nor is it trivial to implement. With the hints I got in some public web forums I implementet the solution provided here.

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.

If someone can show a shrinked but still functional equivalent version that would be great. In the end I think that it would be better if such a solution would be included into a Qt release, especially because in its current form I use so much of their code.

Sample Project

(weiterlesen…)