wxChoice 在 wxPanel 中不可见

wxChoice not visible in wxPanel

我需要在面板中添加一个下拉框,但添加后它似乎没有显示。

WeldProfileDialog::WeldProfileDialog(cMainWindow* parent, wxWindowID id) : wxDialog(parent,id, "Weld Profile Editor")
{
    wxBoxSizer* mainSizer = DBG_NEW wxBoxSizer(wxHORIZONTAL);
    this->SetSizer(mainSizer);
    
    wxBoxSizer* col1Sizer = DBG_NEW wxBoxSizer(wxVERTICAL);
    wxPanel* sidebar = DBG_NEW wxPanel(this, wxID_ANY);
    sidebar->SetSizer(col1Sizer);
    mainSizer->Add(sidebar);

    wxChoice* selectProfileType = DBG_NEW wxChoice(this, wxID_ANY);
    vector<wxString> choices = { "Single V", "Double V", "J Groove", "Compound"};
    selectProfileType->Append(choices);
    selectProfileType->SetSelection(0);
    col1Sizer->Add(selectProfileType, 1, wxEXPAND);
}

但是,当我移除面板并将其直接添加到 box sizer 时,它工作得很好。

而且我不太确定我错过了什么。

WeldProfileDialog::WeldProfileDialog(cMainWindow* parent, wxWindowID id) : wxDialog(parent, id, "Weld Profile Editor")
{
    wxBoxSizer* mainSizer = DBG_NEW wxBoxSizer(wxHORIZONTAL);
    this->SetSizer(mainSizer);
    
    wxBoxSizer* col1Sizer = DBG_NEW wxBoxSizer(wxVERTICAL);
    //wxPanel* sidebar = DBG_NEW wxPanel(this, wxID_ANY);
    //sidebar->SetSizer(col1Sizer);
    mainSizer->Add(col1Sizer);

    wxChoice* selectProfileType = DBG_NEW wxChoice(this, wxID_ANY);
    vector<wxString> choices = { "Single V", "Double V", "J Groove", "Compound"};
    selectProfileType->Append(choices);
    selectProfileType->SetSelection(0);
    col1Sizer->Add(selectProfileType, 1, wxEXPAND);
}

正如@Igor 所发现的那样:问题是我的控件是 window 而不是面板的子控件,它将它放在面板下面。

这个:

wxChoice* selectProfileType = DBG_NEW wxChoice(this, wxID_ANY);

进入这个:

wxChoice* selectProfileType = DBG_NEW wxChoice(sidebar, wxID_ANY);