Resize wx.grid column width?

2,340 views
Skip to first unread message

leonidwang

unread,
Jul 3, 2011, 10:44:51 PM7/3/11
to wxpytho...@googlegroups.com
I'd like to specify the column width ratios of a grid, and when the window is
resized, the column width resized too, but still locked to that ratio. I'm
not sure how to do that, here's my solution:

def UpdateColWidth(self):
width, height = self.GetSizeTuple()
for i in xrange(self.GetNumberCols()):
colwidth = self.colratio[i] * width
self.SetColSize(i, colwidth)

colratio is a list of column ratios, say [0.4, 0.3, 0.3] for a 3 column
grid.
This function works, but only for grid cells, not the column labels.
If I maximums the window and calls UpdateColWidth, the cells expand to
proper width, but the column labels' width stay unchanged.

However, I noticed, if I minimizes/restores the window, the column label's
width will be updated.
Or if I switch to other window to overlap the grid, then the overlapped area
of the column label will be redrawn.
What's event for minimize/restore or overlap window? Can I use that event?

Anyway, back to my problem, how to change column width when the window is
resized?

Thanks


Leo

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/Resize-wx-grid-column-width-tp4548847p4548847.html
Sent from the wxPython-users mailing list archive at Nabble.com.

leonidwang

unread,
Jul 3, 2011, 11:07:34 PM7/3/11
to wxpytho...@googlegroups.com
I figured it out...

SetColWidth() does not refresh the grid. You have to call ForceRefresh() to
see the changes.

http://docs.wxwidgets.org/2.8/wx_wxgrid.html#wxgridsetcolsize

cheers

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/Resize-wx-grid-column-width-tp4548847p4548869.html

Reply all
Reply to author
Forward
0 new messages