PyGTK TreeView 中的粗体/非粗体行

发布于 2024-12-21 00:29:31 字数 91 浏览 2 评论 0原文

我想将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我乃一代侩神 2024-12-28 00:29:31

我假设您有一个模型,其中包含带有一些文本的列,并且 gtk.CellRendererText 小部件的 text 属性设置为该模型中的列索引。

如果向该模型添加新列,则可以使用它来设置每个单元格渲染器中使用的字体粗细。为此,只需将 gtk.CellRendererText 小部件 weight 属性设置为模型中的新列索引,并将 weight-set 设置为 True

之后,您只需使用任何 pango.WEIGHT 常量(例如 pango.WEIGHT_NORMALpango.WEIGHT_BOLD)在模型中设置字体粗细代码>.

举个例子,假设这些是您的模型列(一列用于文本,一列用于字体粗细):

Model columns

这些是您添加用于测试的几行:

Model rows

(请注意pango.WEIGHT_NORMAL=400pango.WEIGHT_BOLD=700

使用此模型,您可以创建一个带有列和文本渲染器的 gtk.TreeView

Treeview Hierarchy

在渲染器中,将 text 属性设置为模型中的 text 列:

Cell renderer text

weight属性添加到模型中的 weight 列:

Cell renderer Weight

使用以下命令获得的结果您添加到模型中的测试数据是:

最终结果

您可以在其中看到文本以模型中设置的字体粗细显示。

I assume that you have a model that contains a column with some text and that a gtk.CellRendererText widget has a text 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 widget weight property to the new column index in the model and weight-set to True.

After that, you just need to set the font weight in the model using any of the pango.WEIGHT constants such as pango.WEIGHT_NORMAL and pango.WEIGHT_BOLD.

As an example, let's say that these are your model columns (one for the text, one for the font weight):

Model columns

and these are a couple of rows that you've added for testing:

Model rows

(Note that pango.WEIGHT_NORMAL=400 and pango.WEIGHT_BOLD=700)

With this model, you create a gtk.TreeView with a column and a text renderer:

Treeview hierarchy

In the renderer you set the text property to the text column in the model:

Cell renderer text

and the weight property to the weight column in the model:

Cell renderer weight

The result that you obtain with the test data that you added to your model is:

Final result

Where you can see that the text is displayed with the font weight that is set in the model.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文