PyGTK TreeView 中的粗体/非粗体行
我想将 TreeView 中的一些行设为粗体,而有些行则不将它们附加到 TreeView,稍后,我想在单击时取消粗体行。
做到这一点最简单的方法是什么?
I want to make some rows in my TreeView bold, and some not as I append them to TreeView, later on, I want to unbold rows on click.
What is the easiest way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您有一个模型,其中包含带有一些文本的列,并且
gtk.CellRendererText
小部件的text
属性设置为该模型中的列索引。如果向该模型添加新列,则可以使用它来设置每个单元格渲染器中使用的字体粗细。为此,只需将
gtk.CellRendererText
小部件weight
属性设置为模型中的新列索引,并将weight-set
设置为True
。之后,您只需使用任何
pango.WEIGHT
常量(例如pango.WEIGHT_NORMAL
和pango.WEIGHT_BOLD
)在模型中设置字体粗细代码>.举个例子,假设这些是您的模型列(一列用于文本,一列用于字体粗细):
这些是您添加用于测试的几行:
(请注意
pango.WEIGHT_NORMAL=400
和pango.WEIGHT_BOLD=700
)使用此模型,您可以创建一个带有列和文本渲染器的
gtk.TreeView
:在渲染器中,将
text
属性设置为模型中的text
列:和
weight
属性添加到模型中的weight
列:使用以下命令获得的结果您添加到模型中的测试数据是:
您可以在其中看到文本以模型中设置的字体粗细显示。
I assume that you have a model that contains a column with some text and that a
gtk.CellRendererText
widget has atext
property set to the column index in that model.If you add a new column to that model you can use it to set the font weight used in every cell renderer. To do that just set the
gtk.CellRendererText
widgetweight
property to the new column index in the model andweight-set
toTrue
.After that, you just need to set the font weight in the model using any of the
pango.WEIGHT
constants such aspango.WEIGHT_NORMAL
andpango.WEIGHT_BOLD
.As an example, let's say that these are your model columns (one for the text, one for the font weight):
and these are a couple of rows that you've added for testing:
(Note that
pango.WEIGHT_NORMAL=400
andpango.WEIGHT_BOLD=700
)With this model, you create a
gtk.TreeView
with a column and a text renderer:In the renderer you set the
text
property to thetext
column in the model:and the
weight
property to theweight
column in the model:The result that you obtain with the test data that you added to your model is:
Where you can see that the text is displayed with the font weight that is set in the model.