[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 » Sat Jun 27, 2009 5:10 pm

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 » Sat Jun 27, 2009 7:02 pm

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 » Sat Jun 27, 2009 7:51 pm

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 » Sat Jun 27, 2009 10:36 pm

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: 1594
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Re: [wxSpinCtrl] minimal size

Post by catalin » Sat Jun 27, 2009 10:37 pm

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 » Sun Jun 28, 2009 5:57 pm

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 » Mon Jul 20, 2009 3:12 pm

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 » Mon Jul 20, 2009 5:25 pm

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 » Mon Jul 20, 2009 5:47 pm

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 » Mon Jul 20, 2009 6:59 pm

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: 1594
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Post by catalin » Mon Jul 20, 2009 8:23 pm

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 » Thu Jul 23, 2009 9:09 am

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