How do I set a minimum window size in wxWidgets?
Asked Answered
T

4

11

This is the hierarchy of widgets I've got:

Frame > wxBoxSizer > wxPanel > wxBoxSizer > wxFlexGridSizer (2 columns, 9 rows), with assorted form fields and buttons inside.

The first BoxSizer is to place the panel in, and the second is to make a border around the FlexGrid.

Everything looks nice, and the frame can expand properly if the window is enlarged, but it also can be resized to almost nothing, hiding all form elements.

How do I force the minimum size for the window to the one suggested by the FlexGridSizer by default (all form elements visible and having their minimal possible sizes)?

Trapezoid answered 4/3, 2009 at 18:27 Comment(0)
L
7

Using the SetMinSize() method on your Frame to set a minimum size will set a limit on the smallest area of the frame (just tested it). Once set, wxWidgets will not allow the frame to be sized smaller than the value specified.

I'd set the value like this. In the constructor, set up all the elements of the frame. At the end, after you call the Layout() method to setup all the sizers and such, call the GetSize(int *w, int *h) method to get the x and y size of your frame at the default layout. Use those values to call the SetMinSize() method to set that default size as the minimum for your Frame. This will take into account all the various padding and borders and such set up by the frame and the contained elements.

Laryngeal answered 5/3, 2009 at 18:30 Comment(0)
M
19

Probably much too late but the answers given here are needlessly complicated, you just need to call SetSizerAndFit(sizer) to both associate the sizer with the frame, set its initial size and also set this size as minimal acceptable size.

Maurilia answered 12/2, 2010 at 22:2 Comment(1)
Not too late for your answer to be raised!Tramontane
L
7

Using the SetMinSize() method on your Frame to set a minimum size will set a limit on the smallest area of the frame (just tested it). Once set, wxWidgets will not allow the frame to be sized smaller than the value specified.

I'd set the value like this. In the constructor, set up all the elements of the frame. At the end, after you call the Layout() method to setup all the sizers and such, call the GetSize(int *w, int *h) method to get the x and y size of your frame at the default layout. Use those values to call the SetMinSize() method to set that default size as the minimum for your Frame. This will take into account all the various padding and borders and such set up by the frame and the contained elements.

Laryngeal answered 5/3, 2009 at 18:30 Comment(0)
T
2

In wxPerl, dagorym's answer can be written concisely as $self->SetMinSize($self->GetSize()); after a call to Layout().

Trapezoid answered 10/3, 2009 at 7:29 Comment(0)
K
1

I would try calling wxFrame->SetMinSize(wxSize) with whatever wxFlexGridSizer->GetMinSize() returns, should work, but not tested. You will need to note what GetMinSize says about coverting to window size before passing it I expect.

Kaminski answered 4/3, 2009 at 20:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.