Can not set color of LevelBar

I have tried to set color of Gtk::Levelbar by using override_color() method of class but it not worked.

then I had tried by using css style by provider by loading css file (my_style.css).

csprovider->load_from_path(“my_style.css”);

cat my_style.css

  • {
    color: rgba(83,165,198,255);
    background: #669999;
    }

by using above css file,I can able to change background color but i can not chnage color of level bar.

please help me on this.

The selectors used by GtkLevelBar are described in the class documentation.

can you please explain me in detail ?

https://gitlab.gnome.org/GNOME/gtk/-/blob/master/tests/testlevelbar.c has an example for custom css in GtkLavelBar

1 Like

The documentation is kind of self-explanatory, but this should give you an idea:

levelbar block.low {
  background-color: blue;
}

levelbar block.high {
  background-color: magenta;
}

Each block in the level bar has a block CSS selector; each level has a CSS class with its own name attached to it.

You should also use the inspector to check the CSS style classes and selectors applied to a widget.

1 Like

Thanks, I will try this.

Thanks.I will look into it.

do you have simiilar kind of example in gtkmm? because i am using gtkmm

I can not compile suggested example.gcc through errors.

I believe that this code will work on GTK3+.

gcc pkg-config --cflags gtk+-3.0 -o testlevelbar testlevelbar.c pkg-config --libs gtk+-3.0

please help me on this.

Matthias linked the code from the master branch, but as you’re using Gtk3, you should use the gtk-3-24 one instead, so here.

1 Like

Do you have same thing in gtkmm ?

There are surely more Gtk demos in C than in every other language, you probably should adapt yourself to translate them into your language of choice. :wink:

But even without translating this demo, you should have a look to the CSS part, as IIUC that’s where your problem lives. CSS works in a way where the more specific rule wins, so you have to find the correct specifier (equal or higher to what the default theme uses) to color a given element. Recheck @ebassi’s comment, that should help you. :smiley:

1 Like

I have translated C code into gtkmm and it works for me.

Thank you @arnaudb and @ebassi.

Do you know how to change boarder color of levelbar ?

Do you know how to change boarder color of levelbar ?