Is there a way to determine the width needed to display a grid without a
horizontal scrollbar even when a vertical scrollbar is displayed.
I added a grid to a vertical box sizer on a frame. The grid is the
widest thing on the frame. As long as there is no vertical scrollbar,
the entire grid is displayed. However, if I reduce the height of the
frame so that a vertical scrollbar is needed for the grid, the width of
the vertical scrollbar reduces the width of the grid and a horizontal
scrollbar is displayed.
Is there a way to determine the width of a vertical scrollbar or the
height of a horizontal scrollbar. I believe they are different sizes
depending on the operating system and perhaps display themes.
When the above grid is displayed (under GTK, at least), there are a few
pixels of background color to the left and bottom of the grid. If I
resize the frame to eliminate those, the scrollbars return. Is there a
way to have the bottom and right edges of the grid exactly at the edge
of the grid, except for space for an undisplayed vertical scrollbar.
Obviously, both the vertical and the horizontal scrollbars occupy some pixels, and as you wrote their sizes depend on OS and display themes. You have to choose: either you accept that one of the columns is of variable width, or the whole grid, hence the frame are of variable size. You need a method that, gauging the difference between grid.GetSize() and grid.GetClientSize(), checks the number of pixels necessary to show exactly all the columns. This is the code I wrote for my grids:
quote
def SetOptimalSize(grid):
# Resets the grid width to show exactly all columns
GridWidth = 0
for c in range(grid.GetNumberCols() ):
GridWidth += grid.GetColSize(c)
sz = grid.GetSize()
csz = grid.GetClientSize()
delta = sz.width
csz.width + 10 # (I don’t know why, but it seems necessary)
GridWidth += (delta + grid.GetRowLabelSize())
GridHeight = grid.GetColLabelSize() +
grid.GetDefaultRowSize() * grid.VisibleRows
and I called this method in:
grid.init
grid.EndBatch
grid.OnEVT_GRID_ROW_SIZE
grid.SetColAttr
grid.SetRowAttr
grid.SetColSize
grid.SetRowSize
grid.SetNumberCols
grid.SetNumberRows
and all variants of grid.Autosize
Sorry, I didn’t say it was simple, but it works.
Cheers
Is there a way to determine the width needed to display a grid without a
horizontal scrollbar even when a vertical scrollbar is displayed.
I added a grid to a vertical box sizer on a frame. The grid is the
widest thing on the frame. As long as there is no vertical scrollbar,
the entire grid is displayed. However, if I reduce the height of the
frame so that a vertical scrollbar is needed for the grid, the width of
the vertical scrollbar reduces the width of the grid and a horizontal
scrollbar is displayed.
Is there a way to determine the width of a vertical scrollbar or the
height of a horizontal scrollbar. I believe they are different sizes
depending on the operating system and perhaps display themes.
When the above grid is displayed (under GTK, at least), there are a few
pixels of background color to the left and bottom of the grid. If I
resize the frame to eliminate those, the scrollbars return. Is there a
way to have the bottom and right edges of the grid exactly at the edge
of the grid, except for space for an undisplayed vertical scrollbar.
Is there a way to determine the width of a vertical scrollbar or the
height of a horizontal scrollbar. I believe they are different sizes
depending on the operating system and perhaps display themes.
wx.SystemSettings.GetMetric
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!