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?
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?
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):
and these are a couple of rows that you've added for testing:
(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:
In the renderer you set the text
property to the text
column in the model:
and the weight
property to the weight
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.
© 2022 - 2024 — McMap. All rights reserved.