Hiding a sizer and all its contents in wxWidgets using XRC

878 views Asked by At

I am using an .xrc file to setup my wxWidgets GUI. For most GUI elements I can specify <hidden>1</hidden> and the element will not be drawn.

What I'd like is to be able to hide my wxStaticBoxSizer and have it and its contents not be drawn.

It's set up as follows, but adding <hidden>1</hidden> does not have any effect. The static box still draws as does everything it contains.

<object class="wxStaticBoxSizer" name="wxID_ANY">
    <orient>wxVERTICAL</orient>
    <label>Flight Formation</label>
    <object class="sizeritem">
    <flag>wxGROW|wxALL</flag>
    <border>10</border>
    <option>1</option>

Is it possible to hide this wxStaticBoxSizer from the .xrc file?

2

There are 2 answers

1
bogdan On BEST ANSWER

Quick hack: nest the sizer inside a wxPanel and hide the panel.


If you're willing to rebuild the XRC lib, here's a quick patch that will provide the functionality you need.

In src/xrc/xh_sizer.cpp, in the body of wxSizerXmlHandler::Handle_sizer(), add the following right after the call to CreateChildren(parent, true/*only this handler*/);:

// This has to be done after CreateChildren().
if(GetBool(wxT("hideitems"), 0) == 1)
   sizer->ShowItems(false);

That's it. Rebuild the lib, and now you can specify <hideitems>1</hideitems> on a sizer, which means it will be created with all its items hidden.

This will handle all sizers except wxStdDialogButtonSizer, which has separate code. I tested it for wxBoxSizer and wxStaticBoxSizer using the XRC sample. I think I'll send a pull request to add this feature to wx; in the mean time, if anyone could do some more testing on this using a larger application, that would be great.

1
VZ. On

There is no way to hide the sizer in the XRC currently, the best you can do is to call wxSizer::ShowItems() from the code. It probably would make sense to support the "hidden" attribute for the sizers too in the future, although it should probably be called something else to avoid creating the erroneous impression that sizers are windows (which they aren't).

BTW, if you tried to validate your XRC, you would have found out that "hidden" element is not allowed here.