I need to draw an image of a spin box. Really, draw the image, I can't use a 
QSpinBox widget.

So I'm using QStyle:: drawComplexControl() with  QStyle::CC_SpinBox. This works 
well, up to a point.

Now I am ready to size it to fit what I want to put into the control's edit 
field, which may use various fonts, etc. For this it seems logical to use 
QStyle:: sizeFromContents(). For the QSize field I used the obvious thing: the 
size of the bounding box for the text. That didn't work at all- the returned 
size is actually smaller in height than the input contentsSize parameter.

So I looked at the sizeHint() function for the QAbstractSpinBox widget. I was 
astounded to find quite a lot of code with hard-coded constants, the use of 
QLineEdit::sizeHint(), computations on the font metrics, two calls to  
subControlRect(QStyle::CC_SpinBox, &opt,  QStyle::SC_SpinBoxEditField ...), the 
second one with the comment:

         // get closer to final result by repeating the calculation

Why is this so complicated? I could never come up with the complex heuristic 
used for QAbstractSpinBox. 

Is that really what needs to be done? Is there something more obvious that I 
can do? I suppose I could just copy the code, or even create a dummy QSpinBox 
just for the purpose of calling sizeHint(), but that is very unsatisfying.

Is there a better approach?

Thanks in advance!

-John Weeks

_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to