Bold / Unallocated Rows in PyGTK TreeView

I want to make some rows in my TreeView in bold, and some are not the way I add them to the TreeView, later, I want to expand the rows when clicked.

What is the easiest way to do this?

+4
source share
1 answer

I assume that you have a model containing a column with some text and that the gtk.CellRendererText widget has the text property set to the column index in this model.

If you add a new column to this model, you can use it to set the font weight used in each cell renderer. To do this, simply set the gtk.CellRendererText widget weight property to the new column index in the model and from 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 text, one for font weight):

Model columns

and these are a few lines you added for testing:

Model rows

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

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

Treeview hierarchy

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

Cell renderer text

and weight in the weight column in the model:

Cell renderer weight

The result obtained using test data added to your model:

Final result

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

+6
source

Source: https://habr.com/ru/post/1386128/


All Articles