layout = cairo_context.create_layout()
font = pango.FontDescription("Sans")
font.set_size(pango.SCALE * (self.get_property('font_size')))
font.set_style(pango.STYLE_NORMAL)
font.set_weight(pango.WEIGHT_BOLD)
layout.set_font_description(font)
w=800 # the width I want to wrap at
layout.set_width(pango.SCALE * w)
layout.set_wrap(pango.WRAP_WORD)
layout.set_markup("my text to write out and wrap at the right width")
5条答案
按热度按时间t8e9dugd1#
使用gtk.CellRendererText呈现gtk.TreeView中的文本,并且 Package 文本归结为在单元格呈现器上设置正确的属性。为了获得要换行的文本,需要在单元格渲染器上设置
wrap-width
属性(以像素为单位)。您可能还希望将wrap-mode
属性设置为合理的值。例如:不幸的是,如果您希望在列上实现宽度可调的自动换行,PyGTK不会自动为您实现这一点。您应该能够动态设置
wrap-width
以获得正确的效果; gtk. label有这样的known workarounds,sproaty的答案中链接的指南似乎也做了类似的事情。rjee0c152#
这似乎不是GTK的内置功能,但是您可以创建自己的TreeCellRenderer,如下所述:
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
看起来挺复杂的
6yoyoihd3#
针对我的博客文章的答案,是在我弄清楚如何“正确地”做之前,因为Kai已经回答了在我当前使用的自定义渲染器中设置 Package 宽度和 Package 模式在TextCellRenderer上工作:
这显然使用了pango cairo,你必须记住用pango乘以你想要的宽度。SCALE否则它太小了看不见。
xjreopfe4#
在寻找这个问题的解决方案时,我碰巧通过不同的来源把这个放在一起。更改列宽时,文本将动态换行:
mitkmikd5#
我想在Gtk 3.0的Python 3中实现这样的功能。下面的工作,使用穆拉特的答案和Gtk3文档如下所示: