Search code examples
c++wxwidgets

wxChoice not visible in wxPanel


I need to add a drop down box to a panel but it doesn't seem to show up when I add it.

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

No choice control

However, when I remove the panel and add it directly to a box sizer it works just fine.

And I'm not really sure what I'm missing.

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

enter image description here


Solution

  • As spotted by @Igor: The problem was that my control was a child of the window instead the panel, which placed it under the panel.

    this:

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

    into this:

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