在切换事件上更改 wxToolBarToolBase 的图标

Changing icon of wxToolBarToolBase on toggle event

我在 wxToolBar 中有一个切换按钮。

我希望按钮根据其状态显示两个不同的图标(一个图标在 "pressed" 时显示,另一个在 "released" 时显示)。

我试过这个:

// toolbar setup:

muteBtn = toolBar -> AddCheckTool(
      ID_MUTE_BTN,
      wxT( "Mute" ),
      wxBitmap( wxT( "unmute.png" ), wxBITMAP_TYPE_PNG ),
      wxBitmap( wxT( "unmute.png" ), wxBITMAP_TYPE_PNG ),
      wxT( "Enable/Disable sounds" ),
      wxT( "Enable/Disable sounds" )
);

...

// EVT_BUTTON handler:
void MyFrame::MuteChanged( wxCommandEvent& event )
{
    if ( event.IsChecked() )
    {
        Mute();
        muteBtn -> SetNormalBitmap( wxBitmap( wxT( "mute.png" ), wxBITMAP_TYPE_PNG ) );
    }
    else
    {
        Unmute();
        muteBtn -> SetNormalBitmap( wxBitmap( wxT( "unmute.png" ), wxBITMAP_TYPE_PNG ) );
    }
    // also tried refresh and update without success:
    // toolBar -> Refresh();
    // toolBar -> Update();
}

但行为不是我所期望的。而不是:

我得到了:

我似乎在事件处理程序中更改了图标,但位图仅在下一次单击事件时绘制。

我也尝试添加 wxToolBar::Refresh()wxToolBar::Update() [查看代码片段] 但没有成功。

如何获得正确的行为?

wx 的开发人员确认不应使用 wxToolBarToolBase::SetNormalBitmap()

我用wxToolBar::SetToolNormalBitmap:

的方法解决了这个问题
// EVT_BUTTON handler:
void MyFrame::MuteChanged( wxCommandEvent& event )
{
    if ( event.IsChecked() )
    {
        Mute();
        toolBar -> SetToolNormalBitmap( ID_MUTE_BTN, wxBitmap( wxT( "mute.png" ), wxBITMAP_TYPE_PNG ) );
    }
    else
    {
        Unmute();
        toolBar -> SetToolNormalBitmap( ID_MUTE_BTN, wxBitmap( wxT( "unmute.png" ), wxBITMAP_TYPE_PNG ) );
    }
}