如何在wxGrid标题单元格中显示位图?

时间:2014-05-06 15:27:00

标签: grid wxpython

使用wxPython我想只在wxGrid的左上角网格单元格中渲染位图,但不知道如何做到这一点。

我用

获取左上方网格角单元格的Window-Object
mywindow = self.someGrid.GetGridCornerLabelWindow()

但是现在我无法为这些Window-Object设置位图。有人能帮助我吗?

1 个答案:

答案 0 :(得分:1)

您需要创建 GridLabelRenderer wxPython演示中有一个示例,其中包含以下代码:

class MyCornerLabelRenderer(glr.GridLabelRenderer):
    def __init__(self):
        import images
        self._bmp = images.Smiles.getBitmap()

    def Draw(self, grid, dc, rect, rc):
        x = rect.left + (rect.width - self._bmp.GetWidth()) / 2
        y = rect.top + (rect.height - self._bmp.GetHeight()) / 2
        dc.DrawBitmap(self._bmp, x, y, True)

要使用此渲染器,您必须执行以下操作:

g = MyGrid(self, size=(100,100))
g.SetColLabelRenderer(0, MyCornerLabelRenderer())

这会将图像放入第一列。