2

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?

4

2 回答 2

3

快速破解:将 sizer 嵌套在 a 中wxPanel并隐藏面板。


如果您愿意重建 XRC 库,这里有一个快速补丁,它将提供您需要的功能。

src/xrc/xh_sizer.cpp的正文中wxSizerXmlHandler::Handle_sizer(),在对 的调用之后添加以下内容CreateChildren(parent, true/*only this handler*/);

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

而已。重建 lib,现在您可以指定<hideitems>1</hideitems>一个 sizer,这意味着它将在创建时隐藏所有项目。

这将处理除wxStdDialogButtonSizer具有单独代码的所有大小调整器。我测试了它wxBoxSizerwxStaticBoxSizer使用了 XRC 样本。我想我会发送一个拉取请求来将此功能添加到 wx;同时,如果有人可以使用更大的应用程序对此进行更多测试,那就太好了。

于 2015-09-23T13:11:04.483 回答
2

目前没有办法在 XRC 中隐藏 sizer,你能做的最好的就是从代码中调用wxSizer::ShowItems()。将来支持 sizer 的“隐藏”属性可能也是有意义的,尽管它可能应该被称为其他东西以避免产生 sizer 是窗口(它们不是窗口)的错误印象。

顺便说一句,如果您尝试验证您的 XRC,您会发现此处不允许使用“隐藏”元素。

于 2015-09-22T21:26:52.220 回答