Macha Macha - 6 months ago 29
Python Question

Word Wrap in PyGTK TreeView

How can I word wrap text inside a PyGTK TreeView?

Kai Kai

Text in a gtk.TreeView is rendered using a gtk.CellRendererText, and wrapping text comes down to setting the right properties on your cell renderer. In order to get text to wrap, you need to set the wrap-width property (in pixels) on the cell renderer. You probably also want to set the wrap-mode property to something sensible. For example:

renderer.props.wrap_width = 100
renderer.props.wrap_mode = gtk.WRAP_WORD

Unfortunately, if you want adjustable-width word wrapping on a column, PyGTK won't do that for you automatically. You should be able to dynamically set wrap-width to get the right effect though; there are known workarounds like this for gtk.Label, and the guides linked in sproaty's answer seem to do a similar thing.