Bold/Unbold rows in PyGTK TreeView
Asked Answered
L

1

5

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?

Lover answered 13/12, 2011 at 15:0 Comment(0)
D
7

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.

Demicanton answered 13/12, 2011 at 15:33 Comment(3)
Thanks for fast response. I read in doc thigks you just explained. But I don't know how to do that. How to access gtk.CellRendererText? I just created TreeView from Glade and I'm appending rows from my code to it. How can I get renderer from my TreeView, and how to set the gtk.CellRendererText widget weight property to the new column index in the model and weight-set to True? Should I do sth in glade or I do that programatically? I looked doc for gtk.TreeView and didn't find how to work with cell renderers. Can you explain a bit? Sorry, but this is the first time I work with GTK.Lover
I added a complete example with screenshots. I think that should be completely clear.Demicanton
Ah, perfect. I was comfused because I missed the fact that font weight property can be binded to row value i.sstatic.net/Q2ikZ.png. Thank you very much!Lover

© 2022 - 2024 — McMap. All rights reserved.