lumapu
lumapu

Reputation: 195

wxWidgets fitting big wxGrid in wxFlexGridSizer

Problem

I have a wxGrid with many rows (>200) placed inside a wxFlexGridSizer. The problem is that my button below the grid disappears. Same thing with a wxBoxSizer works using the proportion setting.

The result should look like the wxBoxSizer solution. Is there a way to use a wxFlexGridSizer in such situation?

wxBoxSizer (working)

wxBoxSizer ScreenShot

    wxGrid *grid = new wxGrid(this, wxID_ANY);
    grid->CreateGrid(0, 2);
    grid->SetDefaultRowSize(20);
    grid->AppendRows(200);

    wxButton *button = new wxButton(this, wxID_ANY, "button");

    wxBoxSizer *bsMain = new wxBoxSizer(wxHORIZONTAL);
    bsMain->Add(grid, 1, wxALL, 5);
    bsMain->Add(button, 0, wxALL, 5);

    SetSizer(bsMain);

wxGridSizer (not working)

wxFlexGridSizer Screenshot

    wxGrid *grid = new wxGrid(this, wxID_ANY);
    grid->CreateGrid(0, 2);
    grid->SetDefaultRowSize(20);
    grid->AppendRows(200);

    wxButton *button = new wxButton(this, wxID_ANY, "button");

    wxFlexGridSizer *fgsMain = new wxFlexGridSizer(1, 0, 0);
    fgsMain->Add(grid, 1, wxALL, 5);
    fgsMain->Add(button, 0, wxALL, 5);
    fgsMain->AddGrowableRow(0);
    fgsMain->AddGrowableCol(0);

    SetSizer(fgsMain);

I tried to use AddGrowableRow for both rows, proportion setting, wxEXPAND flag.

There is a similar question here, but the solution is a workaround:

Fitting a big grid (wxGrid) in a dialog (wxDialog)

(Screenshoots are made with wxFormBuilder v3.8.1)

Upvotes: 0

Views: 780

Answers (1)

VZ.
VZ.

Reputation: 22688

By default, wxGrid will try to show all of its 200 rows on screen, which won't leave enough place for the button. You may call SetInitialSize() (or specify the initial size when creating the grid in its ctor) to change this.

Unrelated to this question, but I strongly advise you to use more readable wxSizerFlags-based API rather than the old Add() overloads. You also shouldn't hardcode the border size in pixels, this is always wrong for some platforms and gets even worse on high DPI displays (and using wxSizerFlags would have taken care of this automatically).

Upvotes: 1

Related Questions