wxGridCellAttr objects provide a mechanism for altering the display of particular rows, columns, or individual cells within a grid. The grid cell attribute objects operate as overlapping templates, where a partially "filled" attribute will add only its defined sub-attributes when added to another attribute object.

For instance, if you specified a column attribute which defined only color, a row attribute which only defined font, and a cell attribute which defined read-only status, your grid cell renderer would receive an attribute object with each of those properties (and the default properties for the grid).

XXX I'm not particularly clear on what the order is for the combination (i.e. which attribute object overrides which other attribute object).

Object Lifetime


The attribute has a number of properties each of which (with the exception of read-only status) has a Set'Name', a Has'Name' and a Get'Name' method. Read-only status defaults to false, and is always defined.


This table-based example generates an attribute object only if the cell being edited is read-only. Returning a non-null attribute overshadows the default attribute's properties, making the cell read-only. Returning None (null) doesn't overshadow any of the default attribute's properties.

{{{class BasePropertyTable( wxPyGridTableBase):


This example is from the wxPython demo, showing use in rendering code.

class MyCustomRenderer(wxPyGridCellRenderer):
    def Draw(self, grid, attr, dc, rect, row, col, isSelected):
        dc.SetBrush(wxBrush(attr.GetBackgroundColour(), wxSOLID))
        dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height)

        text = grid.GetCellValue(row, col)
        colors = [wxRED, wxWHITE, wxCYAN]
        x = rect.x + 1
        y = rect.y + 1
        for ch in text:
            dc.DrawText(ch, x, y)
            w, h = dc.GetTextExtent(ch)
            x = x + w
            if x > rect.right - 5:

wxGridCellAttr (last edited 2008-03-11 10:50:37 by localhost)

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