Page 1 of 1
[wxSpinCtrl] minimal size
Posted: Sat Jun 27, 2009 5:10 pm
by MoonKid
I create a wxSpinCtrl and it looks like this
The problem is that it is to big. The textfield only need to be width enough to display two numbers.
But I don't know how to do that. All the time the width of the spin ctrl is to big.
This is the code how I create and size the ctrl
Code: Select all
BFTimeCtrl::BFTimeCtrl (wxWindow* pParent,
int iHour /*= 0*/,
int iMinute /*= 0*/)
: wxBoxSizer(wxHORIZONTAL)
{
// hour
pHour_ = new wxSpinCtrl(pParent);
pHour_->SetRange(0, 23);
pHour_->SetValue(iHour);
pHour_->Fit();
// minute
// ...
// sizer
this->Add(pHour_, wxSizerFlags(0).FixedMinSize());
Fit(pParent);
}
Posted: Sat Jun 27, 2009 7:02 pm
by Auria
Try wxWindow methods like SetMaxSize
Posted: Sat Jun 27, 2009 7:51 pm
by MoonKid
Auria wrote:Try wxWindow methods like SetMaxSize
Ok, but how do I know the maxSize? The application run on nettops,big screens, different plattforms with differnent fonts!
Posted: Sat Jun 27, 2009 10:36 pm
by Auria
I don't know if there is a more elegant way to know this; you could just use the GetTextExtents method with the longest text you want the control to be able to display, and then add some space for the arrows - that's the best i can think for
Re: [wxSpinCtrl] minimal size
Posted: Sat Jun 27, 2009 10:37 pm
by catalin
Code: Select all
BFTimeCtrl::BFTimeCtrl (wxWindow* pParent,
int iHour /*= 0*/,
int iMinute /*= 0*/)
: wxBoxSizer(wxHORIZONTAL)
{
// hour
// try this:
wxString testStr( "99" ); // "largest" 2 digits..?
int w, h, someExtraSpace=10;
pHour_ = new wxSpinCtrl(pParent);
pHour_->GetTextExtent( testStr, &w, &h );
wxSize newSize( w + someExtraSpace, -1 ); // -1 for the height; height should already be according to the font used by the window
pHour_->SetSize( newSize );
//___
pHour_->SetRange(0, 23);
pHour_->SetValue(iHour);
//pHour_->Fit(); // is this needed?
// minute
// ...
// sizer
this->Add(pHour_, wxSizerFlags(0).FixedMinSize());
// just calling this->Add(pHour_); here should be enough also
Fit(pParent);
}
Posted: Sun Jun 28, 2009 5:57 pm
by Mojo
It looks like you need to set:
Code: Select all
m_spinCtrl1->SetMinSize( wxSize( 50,-1 ) );
You set 50 or the size you want.
Posted: Mon Jul 20, 2009 3:12 pm
by MoonKid
Mojo wrote:It looks like you need to set:
Code: Select all
m_spinCtrl1->SetMinSize( wxSize( 50,-1 ) );
You set 50 or the size you want.
Did you tested it?
It doesn't work!
Posted: Mon Jul 20, 2009 5:25 pm
by Auria
MoonKid wrote:Mojo wrote:It looks like you need to set:
Code: Select all
m_spinCtrl1->SetMinSize( wxSize( 50,-1 ) );
You set 50 or the size you want.
Did you tested it?
It doesn't work!
I guess he meant SetMaxSize and not SetMinSize
Posted: Mon Jul 20, 2009 5:47 pm
by MoonKid
Auria wrote:I guess he meant SetMaxSize and not SetMinSize
Of course I saw it. :)
I used SetMaxSize()! But it doesn't work!
Posted: Mon Jul 20, 2009 6:59 pm
by MoonKid
Auria wrote:I guess he meant SetMaxSize and not SetMinSize
Of course I saw it. :)
I used SetMaxSize()! But it doesn't work!
Posted: Mon Jul 20, 2009 8:23 pm
by catalin
I don't understand why but I suppose
that didn't work, did it?
Posted: Thu Jul 23, 2009 9:09 am
by MoonKid
catalin wrote:I don't understand why but I suppose
that didn't work, did it? :)
It did. Only the combination of SetSize() and wxSizerFlags(0).FixedMinSize() is successfull. I don't need to understand why SetMaxSize() has no effect. ;)