Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

188
Views
¿Cómo diseñar un GtkLabel con CSS?

Estoy tratando de usar CSS para diseñar un GtkLabel. Me gustaría cambiar el color y el tamaño de fuente de la etiqueta. Aquí está mi código C:

 #include <gtk/gtk.h> int main(int argc, char *argv[]) { gtk_init(&argc, &argv); GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); GtkWidget *label = gtk_label_new("Label"); GtkCssProvider *cssProvider = gtk_css_provider_new(); gtk_css_provider_load_from_path(cssProvider, "theme.css", NULL); gtk_style_context_add_provider(gtk_widget_get_style_context(window), GTK_STYLE_PROVIDER(cssProvider), GTK_STYLE_PROVIDER_PRIORITY_USER); g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL); gtk_container_add(GTK_CONTAINER(window), label); gtk_widget_show_all(window); gtk_main(); }

Aquí está mi CSS en theme.css , actualmente esto solo debería cambiar el color de la fuente:

 GtkLabel { color: green; }

Compilo con:

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

Sin embargo, cuando ejecuto el código, aparece un texto en negro. Si cambio theme.css para usar un nombre de widget o una clase CSS en lugar de GtkLabel , todavía no funciona. Sin embargo, si uso * en lugar de GtkLabel , funciona (aunque no quiero que esto se aplique a todo). Esto significa que el código C debería ser correcto y algo está mal con el CSS.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Actualmente, los proveedores de CSS no se heredan de los contextos de estilo secundarios. Por lo tanto, debe agregar el proveedor de CSS a la pantalla usando gtk_style_context_add_provider_for_screen()

Intenta cambiar

 gtk_style_context_add_provider(gtk_widget_get_style_context(window), GTK_STYLE_PROVIDER(cssProvider), GTK_STYLE_PROVIDER_PRIORITY_USER);

para

 gtk_style_context_add_provider_for_screen(gdk_screen_get_default(), GTK_STYLE_PROVIDER(cssProvider), GTK_STYLE_PROVIDER_PRIORITY_USER);

No creo que gtk admita múltiples pantallas en estos días, pero gtk_widget_get_screen() podría usarse para reemplazar gdk_screen_get_default() .

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!