PyGTK TreeView 中的自动换行 [英] Word Wrap in PyGTK TreeView
问题描述
如何在 PyGTK TreeView 中自动换行文本?
How can I word wrap text inside a PyGTK TreeView?
推荐答案
gtk.TreeView 中的文本使用 gtk.CellRendererText 呈现,而换行文本归结为在单元格呈现器上设置正确的属性.为了让文本换行,您需要在单元格渲染器上设置 wrap-width
属性(以像素为单位).您可能还想将 wrap-mode
属性设置为合理的值.例如:
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
不幸的是,如果您想在列上进行可调整宽度的自动换行,PyGTK 不会自动为您执行此操作.您应该能够动态设置 wrap-width
以获得正确的效果;gtk.Label 有 已知的解决方法,并且 sproaty 的答案中链接的指南似乎做类似的事情.
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.
这篇关于PyGTK TreeView 中的自动换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!