Spacer added to inner wxBoxSizer doesn't work in wxWidgets 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
yukomkom
Earned a small fee
Earned a small fee
Posts: 12
Joined: Mon Nov 07, 2016 10:19 am

Spacer added to inner wxBoxSizer doesn't work in wxWidgets

Post by yukomkom »

I have an issue with spacer inside of the inner wxBoxSizer. Here is the sample code.

Code: Select all

class Frame : public wxFrame
{
public:
    Frame()
        : wxFrame(nullptr,
                  wxID_ANY,
                  wxEmptyString,
                  wxDefaultPosition,
                  wxSize(600, 200))
    {
        wxPanel* panel = new wxPanel(this);

        // Some OUTER SIZER
        wxBoxSizer* mainS = new wxBoxSizer(wxVERTICAL);

        // INNER HORIZONTAL SIZER
        wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);

        wxStaticText* text = new wxStaticText(panel, wxID_ANY, wxT("Some Text"));        
        sizer->Add(text, 0, wxALL, 5);

        wxComboBox* comboBox = new wxComboBox(panel, wxID_ANY, wxT("Combo"));
        sizer->Add(comboBox, 0, wxALL, 5);

        // SPACER
        sizer->Add(0, 0, 1, wxEXPAND, 5);

        wxButton* button = new wxButton(panel, wxID_ANY, wxT("Some button"));
        sizer->Add(button, 0, wxALL, 5);
        mainS->Add(sizer, 0, wxALL, 5); 

        panel->SetSizer(mainS);

        // PANEL SIZER
        wxBoxSizer* panelSizer = new wxBoxSizer(wxHORIZONTAL);
        panelSizer->Add(panel, 1, wxEXPAND, 5);

        SetSizer(panelSizer);
        Layout();
        Centre(wxBOTH);
    }
};

class WxguiApp
    : public wxApp
{
public:
    bool OnInit() override
    {
        Frame* w = new Frame();
        w->Show();
        SetTopWindow(w);

        return true;
    }
};

IMPLEMENT_APP(WxguiApp);
If I remove outer sizer spacer starts working fine. Is it bug in my code? Or maybe some issue with wxWidgets?

I couldn't find answer, maybe someone help? wxWidgets 3.0.2
catalin
Moderator
Moderator
Posts: 1618
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Re: Spacer added to inner wxBoxSizer doesn't work in wxWidgets

Post by catalin »

mainS->Add(sizer, 0, wxALL, 5);
You probably need
mainS->Add(sizer, 0, wxEXPAND|wxALL, 5);
Post Reply