Search code examples
c++wxwidgets

wxWidgets C++ panel is invisible


I am starting to practise my skills with wxWidgets and I wanted to add some panel with two different texts above this slider, but when I tried, the result is invisible:

MainWindow::MainWindow(const wxString& title) : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition) {
    wxMenuBar *menubar;
    wxMenu *file;
    menubar = new wxMenuBar;
    file = new wxMenu;
    file->Append(wxID_OPEN, wxT("&Open"));
    menubar->Append(file, wxT("&File"));
    SetMenuBar(menubar);

    wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
    this->SetSizer(vbox);
    player_widget = new wxWindow(this, wxID_ANY);
    player_widget->SetBackgroundColour(wxColour(wxT("black")));
    vbox->Add(player_widget, 1, wxEXPAND | wxALIGN_TOP);

    wxBoxSizer* bs = new wxBoxSizer(wxHORIZONTAL);
    wxPanel* p1 = new wxPanel(this,wxID_ANY,wxDefaultPosition,wxSize(0,20));
    p1->SetSizer(bs);
    p1->Enable(true);
    p1->Show(true);
    vbox->Add(p1,0,wxEXPAND);

    wxStaticText* text1 = new wxStaticText(this,11, "text 1");
    wxStaticText* text2 = new wxStaticText(this,12, "text 2");
    bs->Add(text1);
    bs->Add(text2);

    timeline = new wxSlider(this, myID_TIMELINE, 0, 0, TIMELINE_MAX);
    vbox->Add(timeline, 0, wxEXPAND);

    wxPanel *controlPanel = new wxPanel(this, wxID_ANY);
    wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);
    controlPanel->SetSizer(hbox);
    vbox->Add(controlPanel, 0, wxEXPAND);
    playpause_button = new wxButton(controlPanel, myID_PLAYPAUSE, wxT("Play"));
    stop_button = new wxButton(controlPanel, myID_STOP, wxT("Stop"));
    volume_slider = new wxSlider(controlPanel, myID_VOLUME, VOLUME_MAX, 0, VOLUME_MAX, wxDefaultPosition, wxSize(100, -1));
    hbox->Add(playpause_button);
    hbox->Add(stop_button);
    hbox->AddStretchSpacer();
    hbox->Add(volume_slider);
}

Any ideas what I did wrong?


Solution

  • Change parent of text1 and text2 to p1.