You have to do it manually by calculating the position and size of the label, and then using a DC to draw the color. I had been planning to add this for a while into Dabo's dGrid class, and your question gave me the push I needed. Here's the current version of the code that fires in response to Paint events in dGrid; in a Dabo grid, Columns are objects that contain the properties that control how each grid column is displayed. So with the code below, all you have to do to set the background of the third column's label to yellow would be to write: grid.Columns[2].HeaderBackgroundColor = "yellow"
Anyways, here's the code. It should show you how to determine the area for any column's header label.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def onHeaderPaint(self, evt):
""" Occurs when it is time to paint the grid column headers."""
w = self.Header
dc = wx.ClientDC(w)
clientRect = w.GetClientRect()
font = dc.GetFont()
# Thanks Roger Binns for the correction to totColSize
totColSize = -self.GetViewStart()[0] * self.GetScrollPixelsPerUnit()[0]
# Get the height
ht = self.GetColLabelSize()
for col in range(self.ColumnCount):
dc.SetBrush(wx.Brush("WHEAT", wx.TRANSPARENT))
dc.SetTextForeground(wx.BLACK)
colSize = self.GetColSize(col)
rect = (totColSize, 0, colSize, ht)
colObj = self.Columns[col]
if colObj.HeaderBackgroundColor is not None:
holdBrush = dc.GetBrush()
dc.SetBrush(wx.Brush(colObj.HeaderBackgroundColor, wx.SOLID))
dc.DrawRectangle(rect[0] - (col != 0 and 1 or 0),
rect[1],
rect[2] + (col != 0 and 1 or 0),
rect[3])
dc.SetBrush(holdBrush)
totColSize += colSize
if self.Columns[col].Field == self.sortedColumn:
font.SetWeight(wx.BOLD)
# draw a triangle, pointed up or down, at the top left
# of the column. TODO: Perhaps replace with prettier icons
left = rect[0] + 3
top = rect[1] + 3
dc.SetBrush(wx.Brush(self.sortArrowColor, wx.SOLID))
if self.sortOrder == "DESC":
# Down arrow
dc.DrawPolygon([(left,top), (left+6,top), (left+3,top+6)])
elif self.sortOrder == "ASC":
# Up arrow
dc.DrawPolygon([(left+3,top), (left+6, top+6), (left, top+6)])
else:
# Column is not sorted, so don't draw.
pass
else:
font.SetWeight(wx.NORMAL)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
___/
/
__/
/
____/
Ed Leafe
http://leafe.com/
http://dabodev.com/
···
On Jun 24, 2005, at 6:22 PM, <Henning.Ramm@mediapro-gmbh.de> wrote:
Is there a way to colorize single labels of a wx.grid.Grid,
i.e. SetLabelBackgroundColour not for all labels, bur for only one?