Size of a wxSpinCtrl

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
mbeardsley
Experienced Solver
Experienced Solver
Posts: 74
Joined: Thu Sep 25, 2014 7:40 pm

Size of a wxSpinCtrl

Post 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.

Thanks.
User avatar
doublemax
Moderator
Moderator
Posts: 19103
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Size of a wxSpinCtrl

Post 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.
Use the source, Luke!
Manolo
Can't get richer than this
Can't get richer than this
Posts: 827
Joined: Mon Apr 30, 2012 11:07 pm

Re: Size of a wxSpinCtrl

Post 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));
m_spinctrl->SetMinSize(size);
m_spinctrl->SetSize(size);
In you case, smax would be a wxString('9'). 9 is for a "large" char ('1' is narrow depending on the used font).
mbeardsley
Experienced Solver
Experienced Solver
Posts: 74
Joined: Thu Sep 25, 2014 7:40 pm

Re: Size of a wxSpinCtrl

Post by mbeardsley »

Yes, that works quite well. In my case, I need to set the max size.

Thank You.
Post Reply