Home > Gtk+ > Gtk+ 3.0 Client Side Theme

Gtk+ 3.0 Client Side Theme

How to override user’s theme or I want my app with green buttons.

#include 

static gboolean
delete_event (GtkWidget *widget, GdkEvent *event, gpointer data)
{
	gtk_main_quit();
}

int
main (int argc, char* argv[])
{
  gtk_init(&argc, &argv);

  GtkCssProvider *provider = gtk_css_provider_new ();

  gtk_css_provider_load_from_data (
    provider,
    "GtkButton {font: Monospace 10; background-color: rgba(0%, 76%, 0%, 0.6);}",
    -1, NULL);

  GdkDisplay *display = gdk_display_get_default ();
  GdkScreen *screen = gdk_display_get_default_screen (display);

  gtk_style_context_add_provider_for_screen (
    screen, GTK_STYLE_PROVIDER (provider),
    GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);

  g_object_unref (provider);

  GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_container_set_border_width (GTK_CONTAINER (window), 10);
  g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (delete_event), NULL);

  GtkWidget *button = gtk_button_new_with_label("GtkCssProvider load from data");
  gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (button));
  gtk_widget_show_all (GTK_WIDGET (window));

  gtk_main ();
  return 0;
}
Advertisement
Categories: Gtk+
  1. July 1, 2011 at 4:20 pm | #1

    Saving post man
    You should publish it somewhere accessible to the newcomers to Gtk development.

  2. Mark
    September 10, 2011 at 3:41 am | #2

    Nice tutorial !
    How can you put a image on the background of just the main window using css?

  3. james
    September 12, 2011 at 5:18 am | #3

    You’ve declared the return type of the function delete_event as a static gboolean but haven’t provided one in the function. Also the include is incomplete. It should be: #include
    Other than that well done. I’d like to see more advanced use of css.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.