check_box.rst 1.5 KB
Newer Older
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
Check Boxes
===========

..
  image:: ../../img/tutorials/component.png

Check boxes are buttons that display a "checked" indicator next to their
label.

* `Interface guidelines <https://developer.gnome.org/hig/patterns/controls/checkboxes.html>`__

.. tabs::

   .. code-tab:: c

      GtkWidget *check = gtk_check_button_new_with_label ("Show title");

      // "on_toggled" is defined elsewhere
      g_signal_connect (check, "toggled", G_CALLBACK (on_toggled), NULL);

   .. code-tab:: python

      check = Gtk.CheckButton(label="Show title")

      # "on_toggled" is defined elsewhere
      check.connect("toggled", on_toggled)

Lorenz Wildberg's avatar
Lorenz Wildberg committed
28
29
30
31
32
33
34
   .. code-tab:: vala

      var check = new Gtk.CheckButton.with_label ("Show title");

      // "on_toggled" is defined elsewhere
      check.toggled.connect (on_toggled);

Sonny Piers's avatar
Sonny Piers committed
35
36
37
38
39
40
41
   .. code-tab:: js

      const check = new Gtk.CheckButton({ label: "Show title" });

      // "on_toggled" is defined elsewhere
      check.connect("toggled", on_toggled);

42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

Useful methods for the component
--------------------------------

* Check boxes can be set to an "inconsistent" state: a state that is neither
  active nor inactive. You can use the ``set_inconsistent()`` method to set
  this state.
* If you want to enable a mnemonic shortcut for your check box, you can use
  the ``new_with_mnemonic()`` constructor, or the ``set_use_underline()``
  method.


API references
--------------

In the examples we used the following classes:

* `GtkCheckButton <https://docs.gtk.org/gtk4/class.CheckButton.html>`__