简体   繁体   English

是否可以枚举 wxWidgets 中的 wxFrame 子级?

[英]Is it possible to enumerate the wxFrame children in wxWidgets?

I'm using the wxGlade designer to generate the GUI for a small application.我正在使用 wxGlade 设计器为小型应用程序生成 GUI。 It generates a class, inherited from wxFrame, which is the main application window.它生成一个类,继承自 wxFrame,它是主应用程序窗口。 In order to facilitate the maintenance, I'd like to avoid writing additional code in this generated class.为了方便维护,我想避免在这个生成的类中编写额外的代码。

But all the widgets created with the wxGlade are actually created in the auto-generated method do_layout() and it is not possible to access them outside the scope of that generated method in the generated class.但是所有使用 wxGlade 创建的小部件实际上都是在自动生成的方法 do_layout() 中创建的,并且不可能在生成的类中的生成方法的范围之外访问它们。

Is there a way to get pointer of certain widget outside that generated class - by name, by type, by enumerating the children or something like that?有没有办法在生成的类之外获取某个小部件的指针 - 通过名称、类型、枚举子类或类似的东西?

All classes inherited from wxWindow (wxFrame being one of them) have a function " GetChildren ", which returns a list of child windows that you can then enumerate over.从 wxWindow 继承的所有类(wxFrame 是其中之一)都有一个函数“ GetChildren ”,它返回一个子窗口列表,然后您可以对其进行枚举。 If you are looking for a specific field by name then use the " FindWindow " function.如果您要按名称查找特定字段,请使用“ FindWindow ”功能。

Actually I found the answer myself:其实我自己找到了答案:

wxWindowList & children = myframe->GetChildren();
for ( wxWindowList::Node *node = children.GetFirst(); node; node = node->GetNext() )
{
     wxWindow *current = (wxWindow *)node->GetData();

     // .. do something with current
}

May I recommend you try wxFormBuilder .我可以建议您尝试wxFormBuilder I also used wxGlade before, but it presents too much constraints on how you use it.我之前也使用过 wxGlade,但它对您如何使用它提出了太多限制。 For example, with wxFormBuilder you can select 'visibility' (public,protected,private) for each control on the form.例如,使用 wxFormBuilder,您可以为表单上的每个控件选择“可见性”(公共、受保护、私有)。 It can also generate virtual functions for event handlers, so you just derive your class from wxFormBuilder generated class and implement those functions.它还可以为事件处理程序生成虚函数,因此您只需从 wxFormBuilder 生成的类派生类并实现这些函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM