Differences between revisions 5 and 6
Revision 5 as of 2002-04-24 01:10:45
Size: 2406
Editor: anonymous
Comment: missing edit-log entry for this revision
Revision 6 as of 2002-04-24 01:12:26
Size: 2439
Editor: anonymous
Comment: missing edit-log entry for this revision
Deletions are marked like this. Additions are marked like this.
Line 7: Line 7:
    This pure virtual function has a default implementation which will prepare the DC using the given attribute: it will draw the rectangle with the background colour from attr and set the text colour and font.     The default implementation will draw the rectangle with the background colour from attr and set the text colour and font. Not sure what it does if the attribute values are null, or if any attribute showing up here must be fully specified.

wxGridCellRenderer

The cell renderer allows you to customize the display of a particular data type within the grid. For instance, it allows you to display a "colour" data type as a swatch of colour, rather than as a mere plain-text label. The class has a very simple API, using a standard wxDC for drawing into the cell's rectangle. A secondary function of the renderer is the determination of the "best size" for the cell.

  • void Draw(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, const wxRect& rect, int row, int col, bool isSelected) -- Draw the given cell on the provided DC inside the given rectangle using the style specified by the attribute and the default or selected state corresponding to the isSelected value. Keep in mind that this method will be called once for every instance of the data type, which may result in hundreds of calls for every display update of the grid. Care should be taken to make this a very fast method. The default implementation will draw the rectangle with the background colour from attr and set the text colour and font. Not sure what it does if the attribute values are null, or if any attribute showing up here must be fully specified. Note: This method is used for drawing both selected and unselected cells. To make your renderer consistent with the built-in renderers, you will need to use the colours and fonts used by the grid. As far as I can see, these are the normal default values:

    • font -- wxNORMAL_FONT (I'm guessing that grid.GetFont() would be the real source?)

    • unselected text -- wxSystemSettings_GetColour( wxSYS_COLOUR_WINDOWTEXT  )

    • unselected background -- wxSystemSettings_GetColour( wxSYS_COLOUR_WINDOW  )

    • selected text -- wxSystemSettings_GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT )

    • selected background -- wxSystemSettings_GetColour( wxSYS_COLOUR_HIGHLIGHT )

  • wxSize GetBestSize(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, int row, int col) -- Get the preferred size of the cell for its contents. Note: this size determines both the viewing and editing size of the cell, so care should be taken to allow enough space for the editing controls for the data type.

  • Clone() -- Create a duplicate renderer, normally you can use return self.__class__() as seen for the cell editor.

Back to the ["wxGrid Manual"]

wxPyGridCellRenderer (last edited 2008-03-11 10:50:18 by localhost)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.