How can I word wrap text inside a PyGTK TreeView?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
The answer directing at my blog post, was from before I figured out how to do it 'properly' as Kai already answered just setting wrap width and wrap mode works on a TextCellRenderer in my current custom renderer I use:
this obviously uses pango cairo, and you have to remember to multiple the width you want by the pango.SCALE else it is too small to see.
While searching for a solution to this question I happen to put this together via different sources. When you change the column width, the text is wrapped dynamically:
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 thewrap-mode
property to something sensible. For example: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.It seems this isn't a built-in feature of GTK, however you can create your own TreeCellRenderer, as detailed below:
http://danielwould.wordpress.com/2010/01/02/maemo-custom-cell-renderer-for-gtk-treeview-python/
http://www.islascruz.org/html/index.php?blog/show/Wrap-text-in-a-TreeView-column.html
seems pretty complicated though.