Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Word Wrap in PyGTK TreeView

How can I word wrap text inside a PyGTK TreeView?

like image 764
Macha Avatar asked Jan 23 '23 19:01

Macha


1 Answers

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.

like image 198
Kai Avatar answered Feb 01 '23 09:02

Kai