[Interest] Coding a spin box

Etienne Sandré-Chardonnal etienne.sandre at m4x.org
Fri Oct 11 16:00:41 CEST 2013


Dear all,

I would like to implement a "scientific" spin box, with features such as:
1 - Automatic switch to scientific notation if required, but not for simple
numbers
2 - Number precision not limited by display (the edited number can have
much more digits than displayed in non-edit mode)
3 - Handling of units automatically (such as switch from m to nm, µm, km,
etc...)


I managed to subclass QDoubleSpinBox and have 1 working. But 2 and 3 seem
not possible with QDoubleSpinBox.

So:
 - Is this possible to implement it from QAbstractSpinBox? It should be,
but it seems that QAbstractSpinBox was only meant for having a common
interface between Qt spin boxes, and is not really subclassable by the
user. For instance, text() is read-only, and there is absolutely no hint in
the documentation about how to output a different text, as text() cannot be
subclassed (non virtual)

 - I am thinking about redoing everything from scratch, using QStylePainter
functions for drawing the spinbox. However, I cannot understand from
QAbstractSpinBox::paintEvent source how the spinbox text is drawed, as it
seems to be never passed to options and painter. So I'm not sure how to use
it.


Thanks in advance,

Etienne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20131011/495329f3/attachment.html>


More information about the Interest mailing list