我正在使用
wxScrolledWindow
类做一些滚动。滚动工作正常。我也在使用 wxNotebook
在选项卡之间切换。对于这个例子,我有 2 个选项卡。第一个选项卡包含一个标题,然后是一个派生自 ScrolledWidgetsPane
的 wxScrolledWindow
类。第二个选项卡包含一个空白页。ScrolledWidgetsPane
.CustomButton::onPaint(wxPaintEvent&)
方法时才会发生这种情况。如果我在 onPaint
的 CustomButton
方法中注释代码,那么自定义按钮不会重叠到 tab1 的标题部分。 CustomButton::onPaint
里面的代码如下:
void CustomButton::onPaint(wxPaintEvent &event)
{
*If i comment the next three statements then code works fine but if i use them in the program then the above
problem happens*/
wxClientDC dc(this);
dc.SetBrush(wxBrush(wxColour(100, 123,32), wxBRUSHSTYLE_SOLID));
dc.DrawRectangle(0, 0, 100, 40);
}
FirstPage类中的代码(对应tab1的内容)如下:
First_Page::First_Page(wxNotebook *parent): wxPanel(parent, wxID_ANY)
{
wxBoxSizer *verticalSizer = new wxBoxSizer(wxVERTICAL);
wxPanel *headerPanel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(-1, 40));
headerPanel->SetBackgroundColour("red");
verticalSizer->Add(headerPanel, 0, wxEXPAND, 0);
wxBoxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
SetBackgroundColour(wxColour(233,233,233));
ScrolledWidgetsPane* my_image = new ScrolledWidgetsPane(this, wxID_ANY);
sizer->Add(my_image, 1, wxEXPAND);
verticalSizer->Add(sizer, 1, wxEXPAND, 0);
SetSizer(verticalSizer);
}
ScrolledWidgetsPane里面的代码如下:
ScrolledWidgetsPane::ScrolledWidgetsPane(wxWindow* parent, wxWindowID id) : wxScrolledWindow(parent, id)
{
wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
SetBackgroundColour("blue");
// add a series of widgets
for (int w=1; w<=120; w++)
{
CustomButton *b = new CustomButton(this, wxID_ANY);
sizer->Add(b, 0, wxALL, 3);
}
this->SetSizer(sizer);
this->FitInside();
this->SetScrollRate(5, 5);
}
我该如何解决这个问题,这是什么原因?请注意,这仅在我使用 CustomButton 的 onPaint 方法时发生。
附加问题:有没有办法不显示窗口右侧可见的滚动缩略图?那就是隐藏(或不显示)拇指但仍然具有滚动功能。
下面我附上了3张截图。
我该如何解决这个问题,这是什么原因?注意 只有当我使用 CustomButton 的 onPaint 方法时才会发生这种情况。
在油漆处理程序中,您需要使用
wxPaintDC
而不是 wxClientDC
:
void CustomButton::onPaint(wxPaintEvent &event)
{
wxPaintDC dc(this);
...
}
附加问题:有没有办法不显示窗口右侧可见的滚动条?那就是隐藏(或不显示)拇指但仍然具有滚动功能。
在
ScrolledWidgetsPane::ScrolledWidgetsPane
,你应该可以添加
this->ShowScrollbars(wxSHOW_SB_NEVER,wxSHOW_SB_NEVER);
禁用显示滚动条。