问题描述
我在 Windows (wxWidgets-2.8.9) 上使用带有 wxTaskBarIcon 的弹出菜单.如果我用单选项目填充弹出菜单,它们在点击时不会改变状态.弹出菜单列表中的第一项被标记为选中.但是选择任何其他项目不会改变这一点.
I'm using a popup menu with wxTaskBarIcon on windows (wxWidgets-2.8.9).If I fill popup menu with radio items, they do not change state when clicked.First item in popup menu list is marked as selected. But selecting any other item does not change this.
目前没有项目点击事件处理程序(应用程序更像是 UI 原型).我应该在这个处理程序中手动更新项目检查状态还是仍然是框架职责?
Currently there is no item click event handler (application is more like UI prototype). Should i manually update item check status in this handler or it is still framework duty?
推荐答案
您应该使用 EVT_UPDATE_UI(yourCommandID, yourEventHandler)
来检查/取消选中和启用/禁用菜单项.在您的 UpdateUI 事件处理程序中,您应该指定启用项目时的情况例如.你有带有命令 ID_RADIO_1 和 ID_RADIO_2 的单选按钮组,它们应该根据条件进行检查 bool m_SomeConditionVariable
然后你应该为它们创建 2 个事件处理程序,如
You should use EVT_UPDATE_UI(yourCommandID, yourEventHandler)
for checking/unchecking and enabling/disabling menu items.In your UpdateUI event handler you should specify cases when your item is enabledE.g. you have radiobutton group with commands ID_RADIO_1 and ID_RADIO_2 and they should be checked depending on condition bool m_SomeConditionVariable
then you should create 2 event handlers for them like
void OnRadio1UpdateUI(wxUpdateUIEvent & event)
{
event.Checked(m_SomeConditionVariable == true);
}
void OnRadio2UpdateUI(wxUpdateUIEvent & event)
{
event.Checked(m_SomeConditionVariable == false);
}
在这种情况下,仅当变量为假时才检查第一个单选项,当变量为真时将检查第二个单选项.
and in this case first radio item will be checked only when variable is false and second will be checked when variable is true.
您也可以使用计算条件来代替存储变量,例如
You can use also calculated condition instaed of storing variable e.g.
void OnRadio2UpdateUI(wxUpdateUIEvent & event)
{
// Item will be enabled only when text control has non-empty value
event.Enabled(!m_SomeTextCtrl->GetValue().Trim().IsEmpty());
}
这篇关于弹出菜单单选项目检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!