Popup menu radio item checks

点点圈 提交于 2019-12-13 03:25:30

问题


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.

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?


回答1:


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 enabled E.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());
}


来源:https://stackoverflow.com/questions/631580/popup-menu-radio-item-checks

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!