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

发布于 2024-07-07 03:18:00 字数 247 浏览 9 评论 0原文

我正在使用 wxGlade 设计器为小型应用程序生成 GUI。 它生成一个类,继承自wxFrame,它是主应用程序窗口。 为了方便维护,我想避免在这个生成的类中编写额外的代码。

但是使用 wxGlade 创建的所有小部件实际上都是在自动生成的方法 do_layout() 中创建的,并且不可能在生成的类中的生成方法的范围之外访问它们。

有没有办法在生成的类之外获取某些小部件的指针 - 按名称、按类型、通过枚举子级或类似的东西?

I'm using the wxGlade designer to generate the GUI for a small application.
It generates a class, inherited from wxFrame, which is the main application window.
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.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

呆° 2024-07-14 03:18:00

所有从wxWindow继承的类(wxFrame就是其中之一)都有一个函数“GetChildren”,它返回一个子窗口列表,然后您可以对其进行枚举。 如果您要按名称查找特定字段,请使用“FindWindow”功能。

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. If you are looking for a specific field by name then use the "FindWindow" function.

ㄖ落Θ余辉 2024-07-14 03:18:00

其实我自己也找到了答案:

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

     // .. do something with current
}

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
}
梦纸 2024-07-14 03:18:00

我可以推荐你尝试wxFormBuilder。 我之前也用过wxGlade,但是它对你如何使用它带来了太多的限制。 例如,使用wxFormBuilder,您可以为表单上的每个控件选择“可见性”(公共、受保护、私有)。 它还可以为事件处理程序生成虚函数,因此您只需从 wxFormBuilder 生成的类派生类并实现这些函数即可。

May I recommend you try wxFormBuilder. I also used wxGlade before, but it presents too much constraints on how you use it. For example, with wxFormBuilder you can select 'visibility' (public,protected,private) for each control on the form. It can also generate virtual functions for event handlers, so you just derive your class from wxFormBuilder generated class and implement those functions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文