Check box in grid cell

Hello,

I’m a newbie.

I want to have a check box in some grid cells. I’m using a grid

and a grid table. For the check box, I’m using a custom cell

editor, and I was using wx.grid.gridCellBoolRenderer as renderer.

All this works, but I dislike the layout, because it gives a large

black and white check box, so different than the small green one

that comes when launching the editor (I’m on Windows XP). So

I tried to use a custom cell renderer: this one should display an

image of a check box that look like the checkbox control layout.

The image in the renderer should change whether the check control

has been turned on or off. And here are two problems:

  1. I cannot switch the image displayed by the renderer.

    See class CheckBoxCellRenderer in the attached script

  2. When lauching the cell editor, I can’t get the check box be

    centered in the grid cell. I tried to play with wx.ALIGN_…

    options, so I can put it to the right or left, but not in the

    middle. It seems there is always some kind of empty space

    to the right of the box, although there’s no label. See class

    CheckCellEditor in the attached script.

Many thanks.

Raphael

CheckBoxInGridCell.py (2.87 KB)

Raph wrote:

Hello,
I'm a newbie.
I want to have a check box in some grid cells. I'm using a grid
and a grid table. For the check box, I'm using a custom cell
editor, and I was using wx.grid.gridCellBoolRenderer as renderer.
All this works, but I dislike the layout, because it gives a large
black and white check box, so different than the small green one
that comes when launching the editor (I'm on Windows XP). So
I tried to use a custom cell renderer: this one should display an
image of a check box that look like the checkbox control layout.
The image in the renderer should change whether the check control
has been turned on or off. And here are two problems:
1. I cannot switch the image displayed by the renderer.
   See class CheckBoxCellRenderer in the attached script

You can simplify this somewhat by not using the memory DC and just using dc.DrawBitmap instead of Blit. Also you can use the width and height from the rectangle passed to the method instead of fetching that from the grid. The image isn't changing because value is a string, so 'value == 0' will always be false.

2. When lauching the cell editor, I can't get the check box be
   centered in the grid cell. I tried to play with wx.ALIGN_...
   options, so I can put it to the right or left, but not in the
   middle. It seems there is always some kind of empty space
   to the right of the box, although there's no label. See class
   CheckCellEditor in the attached script.

Override the SetSize method and use the rectangle passed in to reposition the control.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!