[pygtk] Setting treeview column to fill available space

Jeffrey Barish jeff_barish at earthlink.net
Tue Nov 13 03:45:55 WST 2007


I want to put 3 columns into a treeview and set their initial widths.  It
should be possible to change the width of the first 2 columns directly by
dragging their headers.  The width of the third column should adjust to
fill remaining space.  I demonstrate in the attached program that it is not
possible to get this behavior using set_expand().  Apparently, the expand
property really means what it says: the column will only expand, not
contract, to fill available space.

I found that it is possible to achieve the desired behavior by setting the
sizing type to TREE_VIEW_COLUMN_AUTOSIZE.  The documentation says that with
this sizing type "Columns resize to be the optimal size every time the
model changes."  Maximizing the window or changing the width of the other
columns is not a change in the model, so the documentation is at least
incomplete.  I am, however, glad that there is a way to achieve the result
that I desire.  I wonder whether experts agree that setting the sizing type
to TREE_VIEW_COLUMN_AUTOSIZE and leaving expand at its default value is the
correct solution to my problem.

I should note that with this solution, column.get_width() always returns 0
for the width of the last column, not its actual width.  This behavior
seems like a bug to me.

I would also like to note that the method set_fixed_width and the sizing
type TREE_VIEW_COLUMN_FIXED are named misleadingly as the width can, in
fact, be changed.
-- 
Jeffrey Barish
-------------- next part --------------
A non-text attachment was scrubbed...
Name: colwidth.py
Type: application/x-python
Size: 2052 bytes
Desc: not available
Url : http://www.daa.com.au/pipermail/pygtk/attachments/20071112/e3ecc21d/colwidth.bin


More information about the pygtk mailing list