Page 1 of 1

Size of a wxSpinCtrl

Posted: Fri Nov 21, 2014 8:46 pm
by mbeardsley
How can I set the text width of a wxSpinCtrl ?

The control I want is only supposed to allow a single digit (the min value is 0 and the max is 9), but the control default to a width that would hold like a 15-digit number.
Is there some way to specify the "text width"?

I tried using GetSizeFromTextSize() and using that result to set the Control's size, but that didn't seem to work.

I'd like the width of the text box to "match" the length of the maximum value.

I wouldn't think it would matter, but I am using wxWidgets 3.0.0 on Win7-64.


Re: Size of a wxSpinCtrl

Posted: Sat Nov 22, 2014 12:41 am
by doublemax
There is no API to set just the size of the text control part. You can only set the size of the whole control.

Re: Size of a wxSpinCtrl

Posted: Sat Nov 22, 2014 1:46 am
by Manolo
In the widgets sample, file samples/widgets/spinbtn.cpp, function SpinBtnWidgetsPage::OnButtonSetMinAndMax(), line 463 aprox. you can see an example of what you want.

Code: Select all

wxSize size = m_spinctrl->GetSizeFromTextSize(m_spinctrl->GetTextExtent(smax));
In you case, smax would be a wxString('9'). 9 is for a "large" char ('1' is narrow depending on the used font).

Re: Size of a wxSpinCtrl

Posted: Mon Nov 24, 2014 2:49 pm
by mbeardsley
Yes, that works quite well. In my case, I need to set the max size.

Thank You.