在主框架的面板中创建小部件
Create widgets in panel of Main Frame
首先。我在 AGUIFrame class 中创建了一个名为 DataViewPanel class 的面板,我想使用该面板 class 来管理 GUI 框架的一部分。
file.h
class DataViewPanel : public wxPanel
{
public:
DataViewPanel(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize);
};
//DECLARE_EVENT_TABLE()
};
file.cpp
AGUIFrame::AGUIFrame(wxWindow* parent, int id, const wxString& title, const wxPoint& pos, const wxSize& size)
: wxFrame(parent, id, title, pos, size)
{
wxPanel* dataViewPanel = new DataViewPanel(this, -1, wxDefaultPosition, wxDefaultSize);
}
AGUIFrame::DataViewPanel::DataViewPanel(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size)
: wxPanel(parent, id, pos, size)
{
wxBoxSizer* topSizer = new wxBoxSizer(wxHORIZONTAL);
topSizer->Add(new wxButton(this, wxID_OK, "OK"),
0, // make horizontally unstretchable
wxALL, // make border all around (implicit top alignment)
10);
topSizer->Add(new wxButton(this, wxID_OK, "Button 1"), 0, wxALL, 10);
topSizer->Add(new wxButton(this, wxID_OK, "Button 2"), 0, wxALL, 10);
}
但是,当我在 DataViewPanel 中创建 3 个按钮时,编译后只显示一个按钮。
帮我在Gui Frame中显示面板的3个按钮
您需要将您的 sizer 与面板相关联,如果没有 SetSizer(topSizer)
调用,则不会使用 sizer,因此所有按钮在默认位置保持相互叠加,而不是被正确放置。
首先。我在 AGUIFrame class 中创建了一个名为 DataViewPanel class 的面板,我想使用该面板 class 来管理 GUI 框架的一部分。
file.h
class DataViewPanel : public wxPanel
{
public:
DataViewPanel(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize);
};
//DECLARE_EVENT_TABLE()
};
file.cpp
AGUIFrame::AGUIFrame(wxWindow* parent, int id, const wxString& title, const wxPoint& pos, const wxSize& size)
: wxFrame(parent, id, title, pos, size)
{
wxPanel* dataViewPanel = new DataViewPanel(this, -1, wxDefaultPosition, wxDefaultSize);
}
AGUIFrame::DataViewPanel::DataViewPanel(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size)
: wxPanel(parent, id, pos, size)
{
wxBoxSizer* topSizer = new wxBoxSizer(wxHORIZONTAL);
topSizer->Add(new wxButton(this, wxID_OK, "OK"),
0, // make horizontally unstretchable
wxALL, // make border all around (implicit top alignment)
10);
topSizer->Add(new wxButton(this, wxID_OK, "Button 1"), 0, wxALL, 10);
topSizer->Add(new wxButton(this, wxID_OK, "Button 2"), 0, wxALL, 10);
}
但是,当我在 DataViewPanel 中创建 3 个按钮时,编译后只显示一个按钮。
帮我在Gui Frame中显示面板的3个按钮
您需要将您的 sizer 与面板相关联,如果没有 SetSizer(topSizer)
调用,则不会使用 sizer,因此所有按钮在默认位置保持相互叠加,而不是被正确放置。