Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Ubuntu used to have alternating row colors for gtk TreeView widgets. Some applications still do, like Banshee. Alternating row colors would really help my application (written in python 2.7, and using gi.repository and not pygtk) that I'm developing.

I know I can set a hint with


This isn't working, however. Does anyone know how to enable the alternating row colors?

share|improve this question

Whether or not set_rules_hint(True) will display alternating row colors is up to the theme. With Ubuntu's default, Ambience, there will not be alternating rows. As the documentation states:

Do not use it just because you prefer the appearance of the ruled tree; that's a question for the theme. Some themes will draw tree rows in alternating colors even when rules are turned off, and users who prefer that appearance all the time can choose those themes. You should call this function only as a semantic hint to the theme engine that your tree makes alternating colors useful from a functional standpoint (since it has lots of columns, generally).

That said, you can force it if your really want. For instance, this will work in Ambience:

style_context = self.get_style_context()
css_provider = Gtk.CssProvider()
css = """
    GtkTreeView row:nth-child(even) {
        background-color: shade(@base_color, 0.9);

    GtkTreeView row:nth-child(odd) {
        background-color: shade(@base_color, 1.0);
screen = Gdk.Screen.get_default()
style_context.add_provider_for_screen(screen, css_provider,

Though you need to be aware that it might break in other themes. Some themes will use @theme_base_color instead of @base_color You can of course hard code the color, but who knows how that will look with the user's theme...

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.