1.27 <GtkCheckButton>

Class: <GtkCheckButton>

It derives from <GtkWidget>.

Places a label next to an indicator.

A <GtkCheckButton> is created by calling either check-button:new or check-button:new-with-label.

The state of a <GtkCheckButton> can be set specifically using check-button:set-active, and retrieved using check-button:get-active?.

Inconsistent state

In addition to "on" and "off", check buttons can be an "in between" state that is neither on nor off. This can be used e.g. when the user has selected a range of elements (such as some text or spreadsheet cells) that are affected by a check button, and the current values in that range are inconsistent.

To set a <GtkCheckButton> to inconsistent state, use check-button:set-inconsistent.

Grouping

Check buttons can be grouped together, to form mutually exclusive groups - only one of the buttons can be toggled at a time, and toggling another one will switch the currently toggled one off.

Grouped check buttons use a different indicator, and are commonly referred to as radio buttons.

To add a <GtkCheckButton> to a group, use check-button:set-group.

When the code must keep track of the state of a group of radio buttons, it is recommended to keep track of such state through a stateful <GAction> with a target for each button. Using the toggled signals to keep track of the group changes and state is discouraged.

Shortcuts and Gestures

<GtkCheckButton> supports the following keyboard shortcuts:

  • ␣ or Enter activates the button.

CSS nodes

checkbutton[.text-button][.grouped]
├── check
╰── [label]

A <GtkCheckButton> has a main node with name checkbutton. If the check-button:label or check-button:child properties are set, it contains a child widget. The indicator node is named check when no group is set, and radio if the checkbutton is grouped together with other checkbuttons.

Accessibility

<GtkCheckButton> uses the Gtk.AccessibleRole.checkbox role.

Fields

parent-instance

Properties

Property: check-button:active self

If the check button is active.

Setting active to #t will add the :checked: state to both the check button and the indicator CSS node.

Its value is a boolean.

Set it with (set! (check-button:active self) value).

Property: check-button:child self

The child widget.

Its value is a <GtkWidget>, or #f.

Set it with (set! (check-button:child self) value).

Property: check-button:group self

The check button whose group this widget belongs to.

Its value is a <GtkCheckButton>, or #f.

It can only be set, with (set! (check-button:group self) value).

Property: check-button:inconsistent self

If the check button is in an “in between” state.

The inconsistent state only affects visual appearance, not the semantics of the button.

Its value is a boolean.

Set it with (set! (check-button:inconsistent self) value).

Property: check-button:label self

Text of the label inside the check button, if it contains a label widget.

Its value is a string, or #f.

Set it with (set! (check-button:label self) value).

Property: check-button:use-underline self

If set, an underline in the text indicates that the following character is to be used as mnemonic.

Its value is a boolean.

Set it with (set! (check-button:use-underline self) value).

Procedures

Method: check-button:get-active? self ⇒ %return
Method: get-active? self ⇒ %return

Returns whether the check button is active.

self

Passed: a <GtkCheckButton>.

a <GtkCheckButton>

%return

Returned: a boolean.

whether the check button is active

Method: check-button:get-child self ⇒ %return
Method: get-child self ⇒ %return

Gets the child widget of self or NULL if CheckButton:label is set.

self

Passed: a <GtkCheckButton>.

a <GtkCheckButton>

%return

Returned: a <GtkWidget>, or #f.

the child widget of self

Method: check-button:get-inconsistent? self ⇒ %return
Method: get-inconsistent? self ⇒ %return

Returns whether the check button is in an inconsistent state.

self

Passed: a <GtkCheckButton>.

a <GtkCheckButton>

%return

Returned: a boolean.

#t if self is currently in an inconsistent state

Method: check-button:get-label self ⇒ %return
Method: get-label self ⇒ %return

Returns the label of the check button or NULL if CheckButton:child is set.

self

Passed: a <GtkCheckButton>.

a <GtkCheckButton>

%return

Returned: a string, or #f.

The label self shows next to the indicator. If no label is shown, #f will be returned.

Method: check-button:get-use-underline? self ⇒ %return
Method: get-use-underline? self ⇒ %return

Returns whether underlines in the label indicate mnemonics.

self

Passed: a <GtkCheckButton>.

a <GtkCheckButton>

%return

Returned: a boolean.

The value of the check-button:use-underline property. See check-button:set-use-underline for details on how to set a new value.

Procedure: check-button:new ⇒ %return

Creates a new <GtkCheckButton>.

%return

Returned: a <GtkWidget>.

a new <GtkCheckButton>

Procedure: check-button:new-with-label [label] ⇒ %return

Creates a new <GtkCheckButton> with the given text.

label

Passed, or left out: a string, or #f.

the text for the check button.

%return

Returned: a <GtkWidget>.

a new <GtkCheckButton>

Procedure: check-button:new-with-mnemonic [label] ⇒ %return

Creates a new <GtkCheckButton> with the given text and a mnemonic.

label

Passed, or left out: a string, or #f.

The text of the button, with an underscore in front of the mnemonic character

%return

Returned: a <GtkWidget>.

a new <GtkCheckButton>

Method: check-button:set-active self setting
Method: set-active self setting

Changes the check buttons active state.

self

Passed: a <GtkCheckButton>.

a <GtkCheckButton>

setting

Passed: a boolean.

the new value to set

Method: check-button:set-child self [child]
Method: set-child self [child]

Sets the child widget of self.

Note that by using this API, you take full responsibility for setting up the proper accessibility label and description information for self. Most likely, you’ll either set the accessibility label or description for self explicitly, or you’ll set a labelled-by or described-by relations from child to self.

self

Passed: a <GtkCheckButton>.

a <GtkCheckButton>

child

Passed, or left out: a <GtkWidget>, or #f.

the child widget

Method: check-button:set-group self [group]
Method: set-group self [group]

Adds self to the group of group.

In a group of multiple check buttons, only one button can be active at a time. The behavior of a checkbutton in a group is also commonly known as a radio button.

Setting the group of a check button also changes the css name of the indicator widget’s CSS node to ’radio’.

Setting up groups in a cycle leads to undefined behavior.

Note that the same effect can be achieved via the <GtkActionable> API, by using the same action with parameter type and state type ’s’ for all buttons in the group, and giving each button its own target value.

self

Passed: a <GtkCheckButton>.

a <GtkCheckButton>

group

Passed, or left out: a <GtkCheckButton>, or #f.

another <GtkCheckButton> to form a group with

Method: check-button:set-inconsistent self inconsistent
Method: set-inconsistent self inconsistent

Sets the <GtkCheckButton> to inconsistent state.

You should turn off the inconsistent state again if the user checks the check button. This has to be done manually.

self

Passed: a <GtkCheckButton>.

a <GtkCheckButton>

inconsistent

Passed: a boolean.

#t if state is inconsistent

Method: check-button:set-label self [label]
Method: set-label self [label]

Sets the text of self.

If check-button:use-underline is #t, an underscore in label is interpreted as mnemonic indicator, see check-button:set-use-underline for details on this behavior.

self

Passed: a <GtkCheckButton>.

a <GtkCheckButton>

label

Passed, or left out: a string, or #f.

The text shown next to the indicator, or #f to show no text

Method: check-button:set-use-underline self setting
Method: set-use-underline self setting

Sets whether underlines in the label indicate mnemonics.

If setting is #t, an underscore character in self’s label indicates a mnemonic accelerator key. This behavior is similar to label:use-underline.

self

Passed: a <GtkCheckButton>.

a <GtkCheckButton>

setting

Passed: a boolean.

the new value to set

Signals

Signal: check-button:activate

Connect a handler with (connect object check-button:activate handler). It is called as (handler self).

Emitted to when the check button is activated.

The ::activate signal on <GtkCheckButton> is an action signal and emitting it causes the button to animate press then release.

Applications should never connect to this signal, but use the check-button:toggled signal.

The default bindings for this signal are all forms of the ␣ and Enter keys.

self

Passed: a <GtkCheckButton>.

Signal: check-button:toggled

Connect a handler with (connect object check-button:toggled handler). It is called as (handler self).

Emitted when the buttons’s check-button:active property changes.

self

Passed: a <GtkCheckButton>.

Virtual methods

Virtual method: check-button:do-activate implementor self

To override it in a new class, give register-type #:vfuncs `((activate . ,procedure)). The procedure is called as (procedure self).

implementor

Passed: the class whose implementation to call: <GtkCheckButton>, or a class that derives from it, or its GType number.

self

Passed: a <GtkCheckButton>.

Virtual method: check-button:do-toggled implementor self

To override it in a new class, give register-type #:vfuncs `((toggled . ,procedure)). The procedure is called as (procedure self).

implementor

Passed: the class whose implementation to call: <GtkCheckButton>, or a class that derives from it, or its GType number.

self

Passed: a <GtkCheckButton>.