Re: How to change GTK+3 label color dynamically
- From: Tilo Villwock <codemusings gmail com>
- To: Rúben Rodrigues <ruben_gr live com pt>, Stefan Salewski <mail ssalewski de>, "gtk-app-devel-list gnome org" <gtk-app-devel-list gnome org>
- Subject: Re: How to change GTK+3 label color dynamically
- Date: Thu, 16 Mar 2017 12:20:54 +0100
Am Donnerstag, den 16.03.2017, 09:55 +0000 schrieb Rúben Rodrigues:
Hi,
THanks. This is dynamically? I need in c language if possible :S
Dynamic version:
...
static GtkCssProvider* provider = NULL;
static void
set_label_color(GtkWidget* label, const char* color)
{
const char* format = "label { color: %s; }";
size_t length = strlen(format) - 2 + 1;
char style[length];
sprintf(style, format, color);
if (provider == NULL) {
/* only create and add the provider the first time */
provider = gtk_css_provider_new();
gtk_style_context_add_provider(
gtk_widget_get_style_context(label),
GTK_STYLE_PROVIDER(provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
g_object_unref(provider);
}
gtk_css_provider_load_from_data(provider, style, -1, NULL);
}
...
This might not be ideal in all situations. Just make sure you don't
create a new provider everytime you set a new color. Hope that helps.
--Tilo
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]