c++wxwidgetswxnotebook

wx* layout in wxNotebookPage


i'm trying to program the front-end for a schedule-application. In my main tab should be two lists (one above the other one). But this seems to be impossible (I've sat yesterday the half day and today for three more hours). So this is my result:

enter image description here

And this is the common part of my Code:

    // LayoutManagement - Main
    sizer = new wxBoxSizer(wxVERTICAL);
    this->SetSizer(sizer);

    // Tabpane
    tab_pane = new wxNotebook(this,TAB_PANE);
    sizer->Add(tab_pane,1,wxEXPAND);

    // Overview tab
    wxBoxSizer *ot_sizer = new wxBoxSizer(wxVERTICAL);
    overview_tab = new wxNotebookPage(tab_pane,TAB_OVERVIEW);
    overview_tab->SetSizer(ot_sizer);
    tab_pane->AddPage(overview_tab,_("Countdown und Nachrichten"),true);

    // Schedule
    schedule_list = new wxListBox(overview_tab, SCHEDULE_LIST);
    ot_sizer->Add(schedule_list,1,wxEXPAND);

    // NewsList
    news_list = new wxListBox(overview_tab,NEWS_LIST);
    ot_sizer->Add(news_list,3,wxEXPAND);

And my header (part):

    wxListBox *schedule_list;
    wxBoxSizer *sizer;
    wxListBox *news_list;
    wxNotebook *tab_pane;
    wxNotebookPage *overview_tab, *settings_tab, *about_end_tab;

What i'm doing wrong?

Greetings

Michael

(Sorry for my bad english)


Solution

  • The reason this code is not working is that you have called SetSizer() BEFORE adding the widgets to the sizer. You should either move the call to SetSizer AFTER the addition of widgets to the sizer, or force the sizer to redo the layout after the adds.

    ot_sizer->Add(news_list,3,wxEXPAND);
    
    // all widgest added to sizer, now arrange layout as specified
    ot_sizer->Layout();
    

    This should fix your code for the moment.

    A final comment on the structure of your code: you seem to be constructing everything in one large code section. This is not a great idea. As you continue to add elements to your GUI it is going to become very confusing. It is better to subclass each page and create the widgets that belong to each page in the constructor of that page.

    class cOverviewTab : public wxNotebookPage
    {
    public:
    cOverviewTab() : wxNotebookPage(tab_pane,TAB_OVERVIEW)
    {
      wxBoxSizer *ot_sizer = new wxBoxSizer(wxVERTICAL);
      ot_sizer->Add( new wxListBox(overview_tab, SCHEDULE_LIST) );
      ot_sizer->Add( new wxListBox(overview_tab,NEWS_LIST) );
      SetSizer( ot_sizer );
    }
    };