Autosizing grid's last column

I'm trying to resize the rightmost column of the grid to fill the window it's in, like what ListCtrlAutoWidthMixin does to a list control.

For some reason it doesn't seem to be working cleanly. When you play around with the size of the frame in the attached example, the horizontal scrollbar appears for no apparent reason.

Am I missing something in my calculations? Something else?

gridsize.py (1.22 KB)

Eli Golovinsky wrote:

I'm trying to resize the rightmost column of the grid to fill the window it's in, like what ListCtrlAutoWidthMixin does to a list control.

For some reason it doesn't seem to be working cleanly. When you play around with the size of the frame in the attached example, the horizontal scrollbar appears for no apparent reason.

Am I missing something in my calculations? Something else?

wx.ScrolledWindow uses a scroll unit value which is the number of pixels the window will be scrolled with each step, (a.k.a. the scroll rate.) Because of this the virtual size of the window will always be a multiple of this unit size. So if the size needed by the grid is not an exact multiple of the unit size then it will actually tell the scrollbars that it needs something like width + rate - (width % rate) pixels. To size the columns such that no scrollbar appears then it needs to be the multiple of the scroll rate that is <= width.

···

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

Thanks, your method seems to work.

Is there a way to change the Grid's scroll rate though? The solution would be complete if I could set the horizontal rate to 1 and have the grid snugly up the right side of the window.

I've tried calling SetScrollRate in __init__ and in the EVT_SIZE handler but it seems to have no effect.

Robin Dunn wrote:

···

Eli Golovinsky wrote:

I'm trying to resize the rightmost column of the grid to fill the window it's in, like what ListCtrlAutoWidthMixin does to a list control.

For some reason it doesn't seem to be working cleanly. When you play around with the size of the frame in the attached example, the horizontal scrollbar appears for no apparent reason.

Am I missing something in my calculations? Something else?

wx.ScrolledWindow uses a scroll unit value which is the number of pixels the window will be scrolled with each step, (a.k.a. the scroll rate.) Because of this the virtual size of the window will always be a multiple of this unit size. So if the size needed by the grid is not an exact multiple of the unit size then it will actually tell the scrollbars that it needs something like width + rate - (width % rate) pixels. To size the columns such that no scrollbar appears then it needs to be the multiple of the scroll rate that is <= width.

Eli Golovinsky wrote:

Thanks, your method seems to work.

Is there a way to change the Grid's scroll rate though?

No. IIRC you can change it but the Grid class resets it in a few places internally when it is responding to some events.

···

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