Opened 2 years ago

Closed 2 years ago

#14761 closed defect (fixed)

wxGrid size (height) is too small in a sizer

Reported by: tan Owned by:
Priority: normal Milestone: 2.9.5
Component: wxGrid Version: stable-latest
Keywords: best size sizer Cc: llbatlle@…
Blocked By: Blocking:
Patch: yes

Description

wxGrid has too small height in a sizer. To reproduce set initial size for grid to default wxSize(-1, -1) in the grid sample (patch included).

Attachments (1)

griddemo.cpp.patch download (393 bytes) - added by tan 2 years ago.

Download all attachments as: .zip

Change History (7)

Changed 2 years ago by tan

comment:1 Changed 2 years ago by VZ

  • Resolution set to fixed
  • Status changed from new to closed

(In [72704]) Invalidate wxGrid best size when the grid is changed.

Don't keep using the cached best size if rows/columns are added/removed
to/from wxGrid or resized, doing this meant that we always used the first
computed best size which was way too small after adding rows/columns to the
grid.

There could be more places where the grid best size may need to be invalidated
but this should be a good start.

Closes #14761.

comment:2 Changed 2 years ago by llbatlle

  • Resolution fixed deleted
  • Status changed from closed to reopened

I'm testing r73155, in a code like this:

                _grid = new wxGrid(this, -1);
                _grid->CreateGrid(4, 2);
                _grid->SetColLabelValue(0, _T("Y"));
                _grid->SetColLabelValue(1, _T("Z"));

                /* Required at wx r73155, but wasn't required at
                   wx r72143. No idea why. */
                _grid->InvalidateBestSize();

Notice the InvalidateBestSize() I've had to add since our last wx code use. Without this, the grid gets a very small size, with scrollbars.

I think this ticket is related, so I reopen it.

comment:3 Changed 2 years ago by llbatlle

  • Cc llbatlle@… added

comment:4 Changed 2 years ago by hackish

I agree and I can probably fix this. There are additional items that need to be properly tested and debugged. I'd like to do that first before creating and submitting a patch that fixes this and other issues.

comment:5 Changed 2 years ago by vadz

AFAICS, we just need to invalidate the best size when changing the table. Not sure how it worked before without this to be honest but at least doing this fixes the following test case which didn't work before but does now:

  • samples/minimal/minimal.cpp

    diff --git a/samples/minimal/minimal.cpp b/samples/minimal/minimal.cpp
    index a78e462..9eff9cd 100644
    a b  
    3030    #include "wx/wx.h" 
    3131#endif 
    3232 
     33#include "wx/grid.h" 
     34 
    3335// ---------------------------------------------------------------------------- 
    3436// resources 
    3537// ---------------------------------------------------------------------------- 
    bool MyApp::OnInit() 
    167169    SetMenuBar(menuBar); 
    168170#endif // wxUSE_MENUS 
    169171 
     172    wxSizer* sizer = new wxBoxSizer(wxVERTICAL); 
     173    sizer->Add(new wxStaticText(this, wxID_ANY, "This is a grid")); 
     174 
     175    wxGrid* g = new wxGrid(this, wxID_ANY, wxPoint(10, 40)); 
     176    g->CreateGrid(4, 2); 
     177    g->SetColLabelValue(0, "Y"); 
     178    g->SetColLabelValue(1, "Z"); 
     179    sizer->Add(g); 
     180    SetSizer(sizer); 
     181 
    170182#if wxUSE_STATUSBAR 
    171183    // create a status bar just for fun (by default with 1 pane only) 
    172184    CreateStatusBar(2); 

so I'll commit this soon.

comment:6 Changed 2 years ago by VZ

  • Resolution set to fixed
  • Status changed from reopened to closed

(In [73243]) Invalidate wxGrid best size when its associated table changes.

The number of grid cells changes too, so the old best size can't be used any
more.

Closes #14761.

Note: See TracTickets for help on using tickets.