laishiekai
laishiekai

Reputation: 871

wxWidget: How do change the size of the parent Sizer according to the size of the children sizers?

this is a question about wxBoxSizer. I am implementing a custom wxWidget like collapsible pane.

The problem is: I have a wxBoxSizer (Sizer1), and I add another wxBoxSizer (Sizer2) as its child. If I change the size of Sizer2, How do I make Sizer1 update it's size, automatically or manually?

enter image description here

I have tried to call Fit() and Layout() on Sizer1 after I call SetSize() on Sizer2, but it doesn't change the size for Sizer1.

Please help, thank you!

Upvotes: 3

Views: 1331

Answers (2)

VZ.
VZ.

Reputation: 22753

Layout in wxWidgets always works from top to bottom and changing the size of a sub-window or sub-sizer will never change the size of the containing window on its own. If you do want this to happen, call Fit() on the parent window to tell it that should become as big as required by its children. Notice that calling it on the panel will still not be enough, you need to do it on the top level wxFrame or wxDialog itself, unless you have some free space in it which can be used to accommodate the increasing panel size.

Upvotes: 5

macroland
macroland

Reputation: 1035

wxBoxSizer1 already occupies the whole panel. So unless you change the size of the panel itself, the wxBoxSizer1 wont be resized. You might want to try another size as your main sizer such as wxFlexGridSizer. Here you have more choices for precise control.

Upvotes: 3

Related Questions