wxGrid Bug in SetColLabelSize

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
S.K.
Earned a small fee
Earned a small fee
Posts: 11
Joined: Tue Sep 26, 2017 2:50 pm

wxGrid Bug in SetColLabelSize

Post by S.K. »

Dear commuinity

I fear, I found a bug in wxGrid::SetColLabelSize() with wxGRID_AUTOSIZE, when the label has empty lines. In this case the calculated label size is too small.
This happens beacause wxGrid::GetTextBoxSize() uses wxTextMeasureBase::GetTextExtent() for each line. But this function returns zero for empty lines. That leads to the too small label sizes.

Here some code to reproduce this issue:

Code: Select all

#include <wx/app.h>
#include <wx/frame.h>
#include <wx/sizer.h>
#include <wx/grid.h>


class TestFrame : public wxFrame {
public:
  TestFrame::TestFrame(bool restorePerspective, wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& caption = _T(""), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize) :
    wxFrame(parent, id, caption) {
    
    auto top = new wxBoxSizer(wxVERTICAL);
    auto grid = new wxGrid(this, wxID_ANY);
    grid->SetTable(new wxGridStringTable(30, 12), true);
    grid->SetColLabelValue(0, wxT("1. row \n\n2.row \n\n3.row\n\n4. row"));
    grid->SetRowLabelSize(wxGRID_AUTOSIZE);
    grid->SetColLabelSize(wxGRID_AUTOSIZE);
    top->Add(grid, wxSizerFlags().Expand());
    SetSizerAndFit(top);
  };
   
};

class TestApp : public wxApp {
public:
  virtual bool OnInit() {
    auto frame = new TestFrame(false, nullptr);
    frame->Show();
    return true;
  }
};

wxIMPLEMENT_APP(TestApp);
The lines "3. row" and "4. row" aren't displayed.

A simple workaround is, to add spaces to empty lines.
So, when adjusting line 15 to

Code: Select all

grid->SetColLabelValue(0, wxT("1. row \n \n2.row \n \n3.row\n \n4. row"));
it works as expected.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7477
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxGrid Bug in SetColLabelSize

Post by ONEEYEMAN »

Hi,
The first thing for you to do is to try to reproduce this in the grid sample. If you can't - try to modify the sample _minimally_ so that the issue becomes visible.
Then if it is reproducible - open a ticket at trac.wxwidgets.org by saying:

1. Platform you tested this on.
2. Version of wxWidgets.
3. The toolkit used - Linux only (GTK2/3).
4. Attach a patch to the sample to test possible fix and for the core-dev to see the problem.

You can also send an E-mail to the wx-dev mailing list explaining what you found (possibly even before filing the bug).

Also you will need to clearly describe the steps you tried to reproduce the issue.

This forum is for the people who uses the library. Core developers are not reading it.

Both ML and tracker requires approval so be patient.

Of course if you can debug the issue and come up with the fix it would be even better.

Thank you.
Post Reply