I'm trying to get a ListBox to expand horizontally, but it keeps
coming out with some undetermined fixed horizontal size. That size
might be “the proper minimal size”, but there seems to be some extra
space on the right edge. See file “listbox_panel_layout.png”.
The innermost sizer of 3 is vertical and has a StaticText on top of
the Listbox. This sizer is inside the middle horizontal BoxSizer
with a button to the right of the ListBox sizer. A 3rd outermost
vertical BoxSizer holds everything. This is the desired general
layout.
First, I had been playing with this for a while when the button
suddenly stopped auto-expanding horizontally and became minimally
sized, which is what I wanted all along, but couldn’t figure out the
proper incantation to specifically do this. Is there some
particular parameter that purposefully makes a control “minimally
sized” ?
If you give it a proportion value of 0 and don’t set it to wx.EXPAND, the sizer will leave the widget at its preferred size, which works well if you don’t provide a size on creation or make it wx.Size(-1,-1).
Next, I actually want the ListBox (not the button, of course !) to
auto-expand horizontally to take up all the remaining horizontal
space in the panel which excludes the minimally-sized button. The
wx.EXPAND flag seems to do nothing at all. Does anyone have an idea
?
What you need to do is change two places. First is lines 61-62:
allControls_horzSizer.Add( myList_vertSizer, proportion=0,
flag=achs_borderflags, border=25 )
Here, change proportion=1, which means the myList_vertSizer is allowed to take up 100% of the horizontal space left over once the button’s width and borders are taken into account. Note, here you are actually allowing the sizer to take up that space, so that it can in turn apportion that space to the widget it sizes; you are giving it jurisdiction. In this case, it sizes the listBox, which you already set to wx.EXPAND (in line 54). Expand for a widget means “fill in the direction perpendicular to the orientation of the sizer it is in”. Since listBox is in a vertical sizer, expand here means expand horizontally–which is just what you want. Now that its sizer has the ability to itself take up the space it should work…but…
…the same concern about “limiting the jurisdiction” of a sizer by not allowing it to either have a proportion of 1 or to expand crops up again with the sizer sizing the one we just took care of! It is constrained, too, shown on lines 69-71:
acvs_borderFlags = wx.ALL
panel_vertSizer.Add( allControls_horzSizer, proportion=0,
flag=acvs_borderFlags, border=25 )
So this is saying that when you add the allControls_horzSizer, it should not be allowed to expand within its sizer, panel_vertSizer. Again, expand means to expand in the orientation perpendicular to the sizer. Since its sizer is a vertical sizer, then to not allow it to expand means to not allow it to expand horizontally. And yet it must be allowed, so that it can let myList_vertSizer can in turn let the listBox itself take up 100% of the width. Therefore change the flags above to wx.ALL | wx.EXPAND.
Che
···
On Mon, Jul 26, 2010 at 12:31 AM, Ray Pasco pascor@verizon.net wrote: