Re: How to change GTK+3 label color dynamically



No! This is the ID: https://ibin.co/3FlPSBGuokBB.png

and this is the widget name https://ibin.co/3FlPnPaDN7Zl.png that i used 
in css provider. This is not the problem because in start of the program 
i change the label to other color to understand if css provider is 
working. And works, but when i tried in the middle of the code change 
again with this code don't works..

How can i add a Css class? How it works? I tried insert style classes in 
glade, but the value that i write disappear.

Thanks


On 16-03-2017 13:19, Emmanuele Bassi wrote:
You keep using an id in the selector, but you never show how you set
the id on the widget. I suspect you think the buildable ID you use
with GtkBuilder is also the ID used when theming — which is definitely
not the case. You will need gtk_widget_set_name(), instead. Of course,
that comes with its own set of caveats, most importantly: there's no
uniqueness of widget name enforced by GTK+ itself.

If you want to avoid all of this, use a CSS class; you can add a class
programmatically using gtk_style_context_add_class() or you can
specify the class in the GtkBuilder XML file.

Ciao,
  Emmanuele.


On 16 March 2017 at 12:49, Rúben Rodrigues <ruben_gr live com pt> wrote:
I provide my code in previous emails.

This is my code now:

if(css_provider == NULL){
          css_provider = gtk_css_provider_new();

          gtk_style_context_add_provider
(gtk_widget_get_style_context(GTK_WIDGET(gtk_builder_get_object(builder,"window_Main"))),
                  GTK_STYLE_PROVIDER (css_provider),
                  GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
          g_object_unref(css_provider);

      }
      gtk_css_provider_load_from_data (css_provider,"#label_Sensors {
color: red; }",-1,NULL);


On 16-03-2017 12:41, Tilo Villwock wrote:
Am Donnerstag, den 16.03.2017, 11:58 +0000 schrieb Rúben Rodrigues:
Hi,

This is what i have, and don't works...
The code I provided works. What GTK3 version are you using? Also nobody
will be able to help you if you don't show us your code.

--Tilo
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]