Add multiple panel objects in a sizer Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
joepjac
In need of some credit
In need of some credit
Posts: 1
Joined: Wed Nov 15, 2017 10:21 am

Add multiple panel objects in a sizer

Post by joepjac »

Hello,
In my Dialog I'm having problems adding a panel multiple times to a sizer. Adding has to be done by the user, for instance clicking on a button. In my example I used the OnAbout button.
I'm using it to build up kind of a list consisting of panels. The panels contain images, so I think this is only way.

It looks like the panels are not added to the BoxSizerWhereIWantToAddSomething, but to the MainBoxSizer or main dialog.
Can anyone help?
panels behind sizer
panels behind sizer
wxwidgets_img.png (15.52 KiB) Viewed 849 times
This is my code:

Code: Select all

testDialog::testDialog(wxWindow* parent,wxWindowID id)
{
    //(*Initialize(testDialog)
    Create(parent, wxID_ANY, _("wxWidgets app"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER, _T("wxID_ANY"));
    SetClientSize(wxSize(184,244));
    SetMinSize(wxSize(200,200));
    MainBoxSizer = new wxBoxSizer(wxVERTICAL);
    BoxSizerWithButtons = new wxBoxSizer(wxHORIZONTAL);
    Button1 = new wxButton(this, ID_BUTTON1, _("About"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON1"));
    BoxSizerWithButtons->Add(Button1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 4);
    StaticLine1 = new wxStaticLine(this, ID_STATICLINE1, wxDefaultPosition, wxSize(10,-1), wxLI_HORIZONTAL, _T("ID_STATICLINE1"));
    BoxSizerWithButtons->Add(StaticLine1, 0, wxALL|wxEXPAND, 4);
    Button2 = new wxButton(this, ID_BUTTON2, _("Quit"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON2"));
    BoxSizerWithButtons->Add(Button2, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 4);
    MainBoxSizer->Add(BoxSizerWithButtons, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 4);
    Panel2 = new wxPanel(this, ID_PANEL2, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL|wxFULL_REPAINT_ON_RESIZE, _T("ID_PANEL2"));
    BoxSizerWhereIWantToAddSomething = new wxBoxSizer(wxVERTICAL);
    Panel2->SetSizer(BoxSizerWhereIWantToAddSomething);
    BoxSizerWhereIWantToAddSomething->Fit(Panel2);
    BoxSizerWhereIWantToAddSomething->SetSizeHints(Panel2);
    MainBoxSizer->Add(Panel2, 1, wxALL|wxEXPAND, 5);
    SetSizer(MainBoxSizer);
    SetSizer(MainBoxSizer);
    Layout();

    Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&testDialog::OnAbout);
    Connect(ID_BUTTON2,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&testDialog::OnQuit);
    //*)
}

testDialog::~testDialog()
{
    //(*Destroy(testDialog)
    //*)
}

void testDialog::OnQuit(wxCommandEvent& event)
{
    Close();
}

void testDialog::OnAbout(wxCommandEvent& event)
{
    TestPanel* Panel1 = new TestPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize);
    BoxSizerWhereIWantToAddSomething->Add(Panel1, 1, wxALL|wxEXPAND, 5);
    Layout();
}

Nunki
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 235
Joined: Fri Sep 14, 2012 8:26 am
Location: Kontich, Belgium
Contact:

Re: Add multiple panel objects in a sizer

Post by Nunki »

Hi,
I think you only need to add one vertical sizer to your window. Then add 1 panel to this vertical sizer containing a horizontal sizer for the buttons. Then on About simply add a new panel to the basic vertical sizer like the Test dialog in the next screenshot.
sizers.jpg
regards,
Nunki
Post Reply