wxWidgets 如何修改上下文菜单的hover时背景颜色
时间: 2023-11-06 20:00:27 浏览: 226
要修改wxWidgets上下文菜单的hover时背景颜色,可以使用以下方法:
1. 创建一个自定义的wxMenu类,继承自wxMenu,重载它的DrawItem()函数。
2. 在DrawItem()函数中,检查当前项是否为鼠标悬停的项。如果是,设置绘制背景的颜色。
3. 将自定义的wxMenu类设置为你的wxFrame或wxPanel的上下文菜单。
以下是示例代码:
```
class MyMenu : public wxMenu {
public:
MyMenu() : wxMenu() {}
void DrawItem(wxDC& dc, const wxRect& rect, int itemid, int flags) const override {
// Call the base class DrawItem() to draw the item normally
wxMenu::DrawItem(dc, rect, itemid, flags);
// Check if the item is the hover item
if ((flags & wxMENUITEM_SELECTED) && (flags & wxMENUITEM_HOVER)) {
// Draw a rectangle with the background color you want
dc.SetBrush(wxBrush(wxColour(200,200,200)));
dc.SetPen(wxPen(wxColour(200,200,200)));
dc.DrawRectangle(rect);
}
}
};
// Set the custom menu to your frame or panel
SetPopupMenu(new MyMenu());
```
阅读全文
相关推荐














