wx.Grid not rendering quite right -- Ubuntu

I built a wx.grid object as part of a larger panel with other fields and buttons outside the grid. When it’s displayed on screen, the left edge seems to be truncated,and the gray color background for the column labels is offset several pixels to the right. I’ve looked at it in Ubuntu, KDE, and LXDE. In KDE Itried a number of window themes. It was the same glitch in all of them. Is this something I can correct?

It’s a simple enough object:

**self.colLabels = [“Depth”, “Type”, “Quant”, “Alpha”, “Beta”, “Conf”, **

"Infill", “Thick”, “Plan”, “Rough”, “Feature Comment”]

self.featuregrid = wx.grid.Grid(self)

self.featuregrid.SetDefaultColSize(50, True)

self.featuregrid.SetDefaultRowSize(20, True)

self.featuregrid.CreateGrid(8,11)

self.featuregrid.SetRowLabelSize(0) # Don’t display row labels

self.featuregrid.SetColLabelSize(20)

self.featuregrid.SetColSize(10,200)

self.featuregrid.SetDefaultCellFont(wx.Font(8, wx.SWISS, wx.NORMAL, wx.NORMAL))

for col in range(11):

self.featuregrid.SetColLabelValue(col, self.colLabels[col])

self.featuregrid.SetLabelFont(wx.Font(8, wx.SWISS, wx.ITALIC, wx.NORMAL))

I then add it into a couple of sizers:

self.outersizer = wx.BoxSizer(wx.VERTICAL)

self.featuregridsizer = wx.BoxSizer(wx.HORIZONTAL)

self.featuregridsizer.Add(self.featuregrid, 0, wx.ALL, 5)

self.outersizer.Add(self.featuregridsizer, 0, wx.ALL, 20)

Here’s the result:

On the left side it is probably just the line drawn with the lighter color to give it the 3D effect. If your background wasn't also a light color that would be more obvious. On the right side it is probably the size of the grid widget being slightly larger than the grid itself. Again a change in background color of the parent will be able to verify that.

···

On 5/9/12 10:57 PM, llanitedave wrote:

I built a wx.grid object as part of a larger panel with other fields and
buttons outside the grid. When it's displayed on screen, the left edge
seems to be truncated,and the gray color background for the column
labels is offset several pixels to the right. I've looked at it in
Ubuntu, KDE, and LXDE. In KDE Itried a number of window themes. It was
the same glitch in all of them. Is this something I can correct?

--
Robin Dunn
Software Craftsman

Thanks for that, Robin. Using your advice I was able to get it to render at least evenly, but I still don’t seem to understand the math that it uses to calculate its width. The grid pattern uses the sum of the widths of the columns, but the highlighting seems to depend on the surrounding sizers and their padding – is that correct? I haven’t given the grid widget any particular size, nor its enclosing panel. The panel is supposed to be inheriting its color and size from the parent frame.

I’m still a bit puzzled, obviously…

···

On Monday, May 14, 2012 9:34:55 AM UTC-7, Robin Dunn wrote:

On 5/9/12 10:57 PM, llanitedave wrote:

I built a wx.grid object as part of a larger panel with other fields and

buttons outside the grid. When it’s displayed on screen, the left edge

seems to be truncated,and the gray color background for the column

labels is offset several pixels to the right. I’ve looked at it in

Ubuntu, KDE, and LXDE. In KDE Itried a number of window themes. It was

the same glitch in all of them. Is this something I can correct?

On the left side it is probably just the line drawn with the lighter
color to give it the 3D effect. If your background wasn’t also a light
color that would be more obvious. On the right side it is probably the
size of the grid widget being slightly larger than the grid itself.
Again a change in background color of the parent will be able to verify
that.


Robin Dunn

Software Craftsman

http://wxPython.org

wx.ScrolledWindow (the base class of wxGrid) rounds up the virtual size of the window to be a multiple of the scroll rate, which I think is hard coded for grids to be 15 pixels. This is done to ensure that the scrollbars are able to cause the entire virtual content to be scrolled into view, otherwise there could be up to 15-1 pixels of information that is not visible.

For the Grid class this means that there could be some blank space in the widget around the actual area where the grid is drawn, and depending on the version, platform and some options the header for the column headers could be drawn across the entire width, not just the area occupied by the columns.

···

On 5/15/12 9:13 PM, llanitedave wrote:

Thanks for that, Robin. Using your advice I was able to get it to render
at least evenly, but I still don't seem to understand the math that it
uses to calculate its width. The grid pattern uses the sum of the widths
of the columns, but the highlighting seems to depend on the surrounding
sizers and their padding -- is that correct? I haven't given the grid
widget any particular size, nor its enclosing panel. The panel is
supposed to be inheriting its color and size from the parent frame.

I'm still a bit puzzled, obviously...

--
Robin Dunn
Software Craftsman

Sounds like its just one of those things that I’ll have to play with until I get it right. At least it seems consistent so far on all the versions I’ve tried it on – although I’ve yet to attempt Windows.

···

On Wednesday, May 16, 2012 4:16:02 PM UTC-7, Robin Dunn wrote:

On 5/15/12 9:13 PM, llanitedave wrote:

Thanks for that, Robin. Using your advice I was able to get it to render

at least evenly, but I still don’t seem to understand the math that it

uses to calculate its width. The grid pattern uses the sum of the widths

of the columns, but the highlighting seems to depend on the surrounding

sizers and their padding – is that correct? I haven’t given the grid

widget any particular size, nor its enclosing panel. The panel is

supposed to be inheriting its color and size from the parent frame.

I’m still a bit puzzled, obviously…

wx.ScrolledWindow (the base class of wxGrid) rounds up the virtual size
of the window to be a multiple of the scroll rate, which I think is hard
coded for grids to be 15 pixels. This is done to ensure that the
scrollbars are able to cause the entire virtual content to be scrolled
into view, otherwise there could be up to 15-1 pixels of information
that is not visible.

For the Grid class this means that there could be some blank space in
the widget around the actual area where the grid is drawn, and depending
on the version, platform and some options the header for the column
headers could be drawn across the entire width, not just the area
occupied by the columns.


Robin Dunn

Software Craftsman

http://wxPython.org