CheckButton

This CheckButton toggles the title.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <gtk/gtk.h>

/* signal handler for "toggled" signal of the CheckButton */
static void
toggled_cb (GtkToggleButton *toggle_button,
            gpointer         user_data)
{
  GtkWindow *window = user_data;

  if (gtk_toggle_button_get_active (toggle_button))
      gtk_window_set_title (window, "CheckButton Example");
  else
      gtk_window_set_title (window, "");
}

static void
activate (GtkApplication *app,
          gpointer        user_data)
{
  GtkWidget *window;
  GtkWidget *checkbutton;

  window = gtk_application_window_new (app);
  gtk_window_set_title (GTK_WINDOW (window), "CheckButton Example");
  gtk_window_set_default_size (GTK_WINDOW (window), 300, 100);

  checkbutton = gtk_check_button_new_with_label ("Show Title");
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbutton), TRUE);
  g_signal_connect (GTK_TOGGLE_BUTTON (checkbutton), "toggled", G_CALLBACK (toggled_cb), window);
  gtk_container_add (GTK_CONTAINER (window), checkbutton);
  gtk_widget_show_all (window);
}

int
main (int argc, char **argv)
{
  GtkApplication *app;
  int status;

  app = gtk_application_new ("org.example.checkbutton", G_APPLICATION_FLAGS_NONE);
  g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
  status = g_application_run (G_APPLICATION (app), argc, argv);
  g_object_unref (app);

  return status;
}

In this sample we used the following: