Thank you for your answer.
1)
Omitting proportion works in this case. But what if you want to use
different proportions ? The doc says that AddGrowableCol specifies
that column idx should be grown if there is extra space available to
the sizer. In a special case the column shrinks when little extra
space is available. Example:
import wx
class TestFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "GridBagSizer")
sizer = wx.GridBagSizer()
button = wx.Button(self, -1, "0,0")
sizer.Add(button, pos=(0,0))
button = wx.Button(self, -1, "0,1")
sizer.Add(button, pos=(0,1))
sizer.AddGrowableCol(0, 1)
sizer.AddGrowableCol(1, 2)
self.SetSizer(sizer)
self.Fit()
app = wx.PySimpleApp()
TestFrame().Show()
app.MainLoop()
When the windows width is increased a little bit, then button(0,1)
moves behind button(0,0) because column 1 shrinks.
2)
I did some further experiments with GridBagSizer. Here is another
example where the column sizes are not what I expected:
import wx
class TestFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "GridBagSizer")
sizer = wx.GridBagSizer()
button = wx.Button(self, -1, "0,0")
old_size = button.GetBestSize()
button.SetMinSize((old_size[0] * 3, old_size[1]))
sizer.Add(button, pos=(0,0), span=(1,2))
button = wx.Button(self, -1, "1,0")
sizer.Add(button, pos=(1,0), flag=wx.EXPAND)
button = wx.Button(self, -1, "1,1")
sizer.Add(button, pos=(1,1), flag=wx.EXPAND)
sizer.AddGrowableCol(0)
sizer.AddGrowableCol(1)
self.SetSizer(sizer)
self.Fit()
app = wx.PySimpleApp()
TestFrame().Show()
app.MainLoop()
Row 0 contains an increased button that spans 2 columns. Result:
button(1,0) and button(1,1) do not have the same width. Is this
correct ?
3)
Not all available extra space is distributed over the growable
columns. You can see this effect when you use more columns. Example:
import wx
class TestFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "GridBagSizer")
sizer = wx.GridBagSizer()
for i in range(10):
button = wx.Button(self, -1, "0,%d" % i)
sizer.Add(button, pos=(0,i))
sizer.AddGrowableCol(i)
self.SetSizer(sizer)
self.Fit()
app = wx.PySimpleApp()
TestFrame().Show()
app.MainLoop()
When the width of the window is increased by only a few pixels, no
extra space is distributed. Only when you further increase the window
width, then the space is distributed over the columns.
···
On 2 Feb., 02:15, Robin Dunn <ro...@alldunn.com> wrote:
When you set the columns to be growable you used a proportion = 1 for
each of them. This causes the cols to always be equal width regardless
of what the min size of the items in the col actually are.