1

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)

ravenspoint
  • 19,093
  • 6
  • 57
  • 103
michi.0x5d
  • 959
  • 9
  • 13

2 Answers2

0

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 );
}
};
ravenspoint
  • 19,093
  • 6
  • 57
  • 103
  • Ok, have Adjusted the Code. There seems to be an error in wxW. 2.8, if i use your variant of Add (with only one parameter) then both fields will be shown. But there is one more error: The lists wont be expanded. So i tried to set SizerFlags via class `wxSizerFlags` but thisalso not works. Have tried [this](http://wiki.wxwidgets.org/WxSizer#Window_Size_is_Very_Small) too. (failed) – michi.0x5d May 13 '12 at 16:07
0

I had the same problem, and it took me about 2 hours to fix it.

There is no reason to change other lines in your code. You have just to use the wxPanel class instead of wxNotebookPage to create new pages for the wxNotebook object. This is because wxNotebookPage is just a typedef of wxWindow and wxWindow doesn't have some necessary functionality that the wxPanel has.

Your other code doesn't need modifications for this to work, except that it would be really good as noted above to subclass your pages to avoid GUI mess.

Jonathan S.
  • 5,837
  • 8
  • 44
  • 63