DanOc004
DanOc004

Reputation: 11

WXWidgets Sizers leaving a gap at the side

My project has a BoxSizer on the main frame, that BoxSizer then contains a Panel which as a Gride Sizer. The sizers work as intended untill the windows horizontal size gets beyond a certain point, then nothing will stretch horizontal. When the screen is maximised a gap is on the right, but the elements correctly take up the full vertical height.

MyFrame::MyFrame(const wxString& title,const wxPoint& pos,const wxSize& size)
: wxFrame(NULL,wxID_ANY,title,pos,size){
   box=new wxBoxSizer(wxHORIZONTAL);
   panel=new wxPanel(this);
   grid=new wxGridSizer(14,7,3,3);
   //add all the elements to the grid, in this way
   grid->Add(new CustomButton("Text",panel),1,wxEXPAND);
   panel->SetSizer(grid);
   box->Add(panel);
   this->SetSizer(box);
}

When the screen is maximised it looks like this.

[Boxs text and elements] [Gap] [boarder of windows]

[Boxs text and elements] [Gap] [boarder of windows]

[boarder of windows]

I don't want the gap, I want the boxs to stetch out to the boarder of the window.

Upvotes: 0

Views: 210

Answers (1)

VZ.
VZ.

Reputation: 22688

You must use both non-zero (usually just 1) proportion and wxEXPAND with the top level box sizer too to make your code work as intended. Specifying wxEXPAND for the grid sizer elements is enough to make them expand to the space available in the panel, but the panel itself is not configured to expand to take up all the space in the frame, so it won't.

But actually the case of having a panel inside a frame that you want to expand to fill all the available space is so common, that there is special support for it: in fact, if you don't use the box sizer at all, it will already work correctly because by default the frame will resize its only child to take up all the space inside it.

Upvotes: 1

Related Questions