I'm new to wxWidgets
and DialogBlocks
. I have a form that is created using DialogBlocks and saved as an XRC file. Part of the form has a vertical wxStaticBoxSizer
into which are placed two wxScrolledWindow
elements. I want to only show one at a time based on what data is to be shown to the user, so I have one marked hidden and left the other one visible. When I try to switch the display and show the widget that was hidden in the XRC and hide the one that was not, the one that I hide goes away fine, but the one that I want to show is not visible. If I resize the window however, it appears. Once it has appeared then I can switch back and forth with no issues. I tried many combinations of showing, enabling, invalidating, getting the sizer and calling RecalcSizes
, refresh, layout, and some others. I tried them in different combinations too. Simply calling Show
will allow me to toggle between the two, but only after I switch to the one that does not show initially and resize the window. From what I see in the docs. the issue is that wxSizer
doesn't allocate space for hidden windows, but there is a flag that can be set to override that behavor. My problem is that DialogBlocks does not expose that feature, so if I manually edit the XRC file the modification will be lost when I, or one of the other developers, save, some changes. Is there a sequence of calls that I can make to tell the sizer to allocate space? The default OnResize
handler does something to cause the sizer to allocate space, but I don't know what that is, or how to do it.
This is the flag I found in the docs:
wxRESERVE_SPACE_EVEN_IF_HIDDEN Normally wxSizers don't allocate space for hidden windows or other items. This flag overrides this behavior so that sufficient space is allocated for the window even if it isn't visible. This makes it possible to dynamically show and hide controls without resizing parent dialog, for example. This function is new since wxWidgets version 2.8.8
Unfortunately DialogBlocks indeed doesn't allow you to specify this flag. Without it you need to call Layout()
after showing a previously hidden control. This will work, provided you call it on the parent with sufficient space to accommodate the children which now need more space (e.g. calling it on the top level parent will always work), but will result in controls visibly shifting which may be not what you want.