gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 05:43:32 25 4
gpt4 key购买 nike

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

我希望按钮根据其状态显示两个不同的图标(一个图标在“按下”时显示,另一个在“释放”时显示)。

我试过这个:

// 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();
}

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

  • 启动图标:unmute.png
  • 第一次点击后:mute.png(调用了Mute())
  • 第二次点击后:unmute.png(调用了Unmute())
  • 第三次点击后:mute.png(调用了Mute())
  • ...

我得到了:

  • 启动图标:unmute.png
  • 第一次点击后:unmute.png(调用了Mute())
  • 第二次点击后:mute.png(调用了Unmute())
  • 第三次点击后:unmute.png(调用了Mute())
  • ...

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

我还尝试添加 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 ) );
}
}

关于c++ - 在切换事件上更改 wxToolBarToolBase 的图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30163281/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com