Changing wxGrid Grid Lines

Are you writing your own components and need help with how to set them up or have questions about the components you are deriving from ? Ask them here.
FlyingIsFun1217
Super wx Problem Solver
Super wx Problem Solver
Posts: 497
Joined: Mon Nov 06, 2006 9:58 pm

Changing wxGrid Grid Lines

Postby FlyingIsFun1217 » Wed Nov 18, 2015 7:31 pm

Greetings,

Recently I've been getting back into C++, as well as wxWidgets. I'm currently trying to write a variation on the wxGrid component, in particular attempting to change the way it draws the divider lines through the cells. I noticed in the documentation that it was mentioned to override "GetRowGridLinePen" and return the pen desired to draw out the grid lines. Below is a sampling of what I'm attempting to do.

Code: Select all

MainApp::MainApp(const wxString &title) : wxFrame(NULL, wxID_ANY, title)
{
   GridComponent *gridCompOne = new GridComponent(this, wxID_ANY, wxDefaultPosition, wxSide(400, 400));
}


Code: Select all

GridComponent::GridComponent(wxWindow *parent, wxWindowID id, const wxPoint &gridPos, const wxSize &gridSize) : wxGrid(parent, wxID_ANY, gridPos, gridSize)
{
   wxGrid *gridInstance = new wxGrid(parent, wxID_ANY, gridPos, gridSize);
   gridInstance -> CreateGrid(numRows, 3, wxGridSelectCells);
}

wxPen GridComponent::GetRowGridLinePen()
{
   return wxPen(*wxBLACK, 1, wxPENSTYLE_SHORT_DASH);
}


I have to be missing something. Am I not overriding the GetRowGridLinePen function correctly? Am I going about creating a new component in the wrong way?

Thanks

PB
Part Of The Furniture
Part Of The Furniture
Posts: 1548
Joined: Sun Jan 03, 2010 5:45 pm

Re: Changing wxGrid Grid Lines

Postby PB » Wed Nov 18, 2015 8:45 pm

I must be missing something: Why are you creating a wxGrid instance in the GridComponent ctor? Shouldn't the code be like

Code: Select all

GridComponent::GridComponent(wxWindow *parent, wxWindowID id, const wxPoint &gridPos, const wxSize &gridSize) : wxGrid(parent, wxID_ANY, gridPos, gridSize)
{
   CreateGrid(numRows, 3, wxGridSelectCells);
}


Also the signature for wxGrid::GetRowGridLinePen() is

Code: Select all

virtual wxPen    GetRowGridLinePen (int row)

as it allows you to customize the pen for every row separately. I.e. your method which is missing the row parameter actually does not override anything. Perhaps you meant to override GetDefaultGridLinePen()?

FlyingIsFun1217
Super wx Problem Solver
Super wx Problem Solver
Posts: 497
Joined: Mon Nov 06, 2006 9:58 pm

Re: Changing wxGrid Grid Lines

Postby FlyingIsFun1217 » Fri Nov 20, 2015 12:43 am

Indeed, I was looking at the class inheritance in the wrong way.

And yes, somehow I forget to add in the 'row' parameter to the overridden function.

Thanks!


Return to “Component Writing”

Who is online

Users browsing this forum: No registered users and 1 guest