查找wxMenu的选定电台项目 [英] Finding a wxMenu's Selected Radio Item

查看:104
本文介绍了查找wxMenu的选定电台项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一组无线电项目,位于 wxMenu

Let's say that I have a group of radio items in a wxMenu. I know that exactly one of these will be checked at any given time.

wxMenu 或其他一些结构保持所选项目的索引,或者我需要调用 ischecked ,直到我找到检查的元素来找到它的索引?

Does the wxMenu or some other construct hold onto the index of the checked item, or do I need to call the isChecked on each radio item till I find the checked element to find it's index?

我问过 这个问题 如何做,但我更喜欢wxWidgets保存

I've asked this question about how to do that, but I'd much prefer wxWidgets saved me from doing that everywhere.

推荐答案

否,保存最后一个选定项目的索引(如 ravenspoint的回答)或使用 wxMenuBarBase :: IsChecked(),直到找到所选的单选按钮是唯一的方法。

No, saving the index of the last selected item (as shown in ravenspoint's answer) or using wxMenuBarBase::IsChecked() until you find the selected radio button is the only way to do it.

对于wxWidgets提供对当前选择的按钮的访问,它不仅需要存储它(这意味着不要忘记更新不仅当选择的更改,而且当项目插入/删除从菜单,因此它已经不是完全平凡),但以某种方式提供访问您感兴趣的无线电项目组,这将需要能够识别目前没有办法做,并且添加它不会特别简单。

For wxWidgets to provide access to the currently selected button it would need not only to store it (which means not forgetting to update not only when the selected changes, but also when items are inserted into/deleted from the menu, so it's already not completely trivial), but to somehow provide access to the radio items group you're interested in, which would require being able to identify it and currently there is no way to do it and adding it isn't going to be particularly simple.

然而,可以轻松地做 ,正在写一个可重用的函数 int GetIndexOfSelectedRadioItem(int firstItem)将从给定项目开始并调用 IsChecked()对后续项直到返回true并返回项的偏移量。你应该能够在你自己的代码,但如果你想包括这样的函数在wxWidgets本身(作为一个静态 wxMenuBar 方法,可能),请don 't犹豫发送修补程序/拉请求做它!

What could be done easily, however, is writing a reusable function int GetIndexOfSelectedRadioItem(int firstItem) that would start at the given item and call IsChecked() on subsequent items until it returns true and return the offset of the item. You should be able to do it in your own code, but if you'd like to include such function in wxWidgets itself (as a static wxMenuBar method, probably), please don't hesitate to send patches/pull requests doing it!

这篇关于查找wxMenu的选定电台项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆