OK, now works:

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

apply_css(gtk_builder_get_object(builder,"window_Main"),css_provider);
         g_object_unref(css_provider);

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


static void apply_css(GtkWidget *widget, GtkStyleProvider *provider)
{
gtk_style_context_add_provider(gtk_widget_get_style_context(widget), 
GTK_STYLE_PROVIDER(provider),G_MAXUINT);
     if(GTK_IS_CONTAINER(widget))
         gtk_container_forall(GTK_CONTAINER(widget),(GtkCallback) 
apply_css,provider);

}

I need to create a different selector for each of label that i want to 
change to red color?


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...@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
>
>

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

Reply via email to