I'm attempting to write a custom QDoubleSpinBox
subclass which has a scaling factor / function between it's internal value and the displayed value. The purpose of this is to support displaying the same internal value in different units (e.g. allow the user to select whether to display metres, millimetres or inches, but always store the actual value in metres).
Overriding QDoubleSpinBox::textFromValue
was quite simple to scale the internal value and append a unit symbol. However the valueFromText()
and validate()
methods have a lot of internal logic which enforces the min / max bounds. Since these are in a different unit system to what the user is working in, it limits the user to incorrect min and max values.
Ideally I would like to avoid reimplementing / copy and pasting all of this internal private logic just to implement scaling of the value when parsing it from text. Does anyone have any suggestions on how to avoid this?