I would like to change the label of a button located under wxRibbonButtonBar
. One can access the button by calling the GetItemByID
method of the wxRibbonButtonBar
which returns an object type of wxRibbonButtonBarButtonBase
which is an abstract class with no methods.
I did extensive search but could not find a clear solution on how to change the ribbon buttons in wx dynamically. Any help appreciated:
Below line gives the error:
pointer to incomplete class type is not allowed
this->help_bar->GetItemById(RIBBON_CHECK)
where help_bar
is wxRibbonButtonBar
I found the solution to this problem, while playing with the wx Samples under samples directory of wxWidgets. The ribbon project nicely shows how to tie the change of button labels to an EVT_UPDATE_UI and use of SetText() method of the wxUpdateUIEvent object.
SetText() method does not update the UI, so a repaint or refresh is still needed. I guess this is another question on its own.
I still think this is a very weird way of updating a button label but at least there is an answer :)
Example implementation:
/// Event Table
BEGIN_EVENT_TABLE(SomeClass, MyFrame1)
EVT_UPDATE_UI(RIBBON_HELPOPEN, SomeClass::UpdateRibbonButtonText)
EVT_UPDATE_UI(RIBBON_FITVIEW, SomeClass::UpdateRibbonButtonText)
END_EVENT_TABLE()
void SomeClass::UpdateRibbonButtonText(wxUpdateUIEvent &event) {
if (event.GetId() == RIBBON_HELPOPEN) {
event.SetText(_("Help"));
}
else if (event.GetId() == RIBBON_FITVIEW) {
event.SetText(_("Fit View"));
}
}