[wxSpinCtrl] minimal size Topic is solved

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
MoonKid
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 543
Joined: Wed Apr 05, 2006 9:39 am
Contact:

[wxSpinCtrl] minimal size

Post by MoonKid »

I create a wxSpinCtrl and it looks like this
Image

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);
}
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

Try wxWindow methods like SetMaxSize
"Keyboard not detected. Press F1 to continue"
-- Windows
MoonKid
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 543
Joined: Wed Apr 05, 2006 9:39 am
Contact:

Post 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!
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post 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
"Keyboard not detected. Press F1 to continue"
-- Windows
catalin
Moderator
Moderator
Posts: 1618
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Re: [wxSpinCtrl] minimal size

Post 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);
}
Mojo
Super wx Problem Solver
Super wx Problem Solver
Posts: 401
Joined: Wed Sep 21, 2005 8:17 am
Location: Rostov-on-Don, Southern Russia

Post 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.
Win XP HE SP3, Vista
Xubuntu 12.04 LTS
wxWidgets-2.9.5
wxWidgets-3.0.0
MoonKid
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 543
Joined: Wed Apr 05, 2006 9:39 am
Contact:

Post 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!
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post 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
"Keyboard not detected. Press F1 to continue"
-- Windows
MoonKid
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 543
Joined: Wed Apr 05, 2006 9:39 am
Contact:

Post 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!
MoonKid
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 543
Joined: Wed Apr 05, 2006 9:39 am
Contact:

Post 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!
catalin
Moderator
Moderator
Posts: 1618
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Post by catalin »

I don't understand why but I suppose that didn't work, did it? :)
MoonKid
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 543
Joined: Wed Apr 05, 2006 9:39 am
Contact:

Post 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. ;)
Post Reply