Question

Using wxPython I want to render a bitmap only in the upper left grid corner cell of a wxGrid, but have no idea how to do this.

I get the Window-Object of the left upper grid corner cell with

mywindow = self.someGrid.GetGridCornerLabelWindow()

But now I cannot set a bitmap to these Window-Object. Can anybody help me?

Était-ce utile?

La solution

You will need to create a GridLabelRenderer. There is an example in the wxPython demo that has the following piece of code:

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)

To use this renderer, you will have to do something like this:

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

This will put the image into the first column.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top