2016-06-03 19 views
8

Sto provando css in gtk3 e non capisco come usare una classe specifica.come impostare una specifica classe css su un widget in gtk3? (c)

codice

C:

provider = gtk_css_provider_new(); 
display = gdk_display_get_default(); 
screen = gdk_display_get_default_screen (display); 
gtk_style_context_add_provider_for_screen (screen, GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_USER); 
gtk_css_provider_load_from_path(GTK_CSS_PROVIDER(provider),"styles.css",NULL); 

enter_button = gtk_button_new_with_label("Print"); 
g_signal_connect(G_OBJECT(enter_button), "clicked", G_CALLBACK(print_entry_dialog),&t_data); 
gtk_box_pack_start(GTK_BOX(hbox3), enter_button, TRUE, TRUE, 0); 

Css (styles.css):

GtkButton{ 
    background: #669999; 
    text-shadow: 1px 1px 5px black; 
    box-shadow: 0px 0px 5px black; 
    border: 1px solid black; 
} 

In questo modo funziona: enter image description here

Ma voglio impostare una classe 'enter_button' che imposta le proprietà solo per 'enter_button', non per tutti i widget sotto il nome di GtkButton.

Ho letto su gtk_style_context_add_class() func, ma non so come funzioni con il file 'styles.css'. Cosa dovrei fare?

+1

utilizzare la funzione che avete trovato in combinazione con 'gtk_widget_get_style_context()' https://developer.gnome.org/gtk3/stable/GtkWidget.html#gtk-widget-get-style-context – B8vrede

risposta

9

ho risolto in questo modo:

GtkStyleContext *context; 
enter_button = gtk_button_new_with_label("Print"); 
context = gtk_widget_get_style_context(enter_button); 
gtk_style_context_add_class(context,"enter_button"); 

CSS:

.enter_button{ 
    background: #669999; 
    text-shadow: 1px 1px 5px black; 
    border-radius: 3px; 
    box-shadow: 0px 0px 5px black; 
} 

Per ulteriori informazioni guardare qui: GtkStyleContext examples