1.64 <GtkExpander>

Class: <GtkExpander>

It derives from <GtkWidget>.

Allows the user to reveal or conceal a child widget.

This is similar to the triangles used in a GtkTreeView.

Normally you use an expander as you would use a frame; you create the child widget and use expander:set-child to add it to the expander. When the expander is toggled, it will take care of showing and hiding the child automatically.

Special Usage

There are situations in which you may prefer to show and hide the expanded widget yourself, such as when you want to actually create the widget at expansion time. In this case, create a <GtkExpander> but do not add a child to it. The expander widget has an expander:expanded property which can be used to monitor its expansion state. You should watch this property with a signal connection as follows:

static void
expander_callback (GObject    *object,
                   GParamSpec *param_spec,
                   gpointer    user_data)
{
  GtkExpander *expander;

  expander = GTK_EXPANDER (object);

  if (gtk_expander_get_expanded (expander))
    {
      // Show or create widgets
    }
  else
    {
      // Hide or destroy widgets
    }
}

static void
create_expander (void)
{
  GtkWidget *expander = gtk_expander_new_with_mnemonic ("_More Options");
  g_signal_connect (expander, "notify::expanded",
                    G_CALLBACK (expander_callback), NULL);

  // ...
}

GtkExpander as GtkBuildable

An example of a UI definition fragment with GtkExpander:

<object class="GtkExpander">
  <property name="label-widget">
    <object class="GtkLabel" id="expander-label"/>
  </property>
  <property name="child">
    <object class="GtkEntry" id="expander-content"/>
  </property>
</object>

CSS nodes

expander-widget
╰── box
    ├── title
    │   ├── expander
    │   ╰── <label widget>
    ╰── <child>

<GtkExpander> has a main node expander-widget, and subnode box containing the title and child widget. The box subnode title contains node expander, i.e. the expand/collapse arrow; then the label widget if any. The arrow of an expander that is showing its child gets the :checked pseudoclass set on it.

Accessibility

<GtkExpander> uses the Gtk.AccessibleRole.button role.

Properties

Property: expander:child self

The child widget.

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

Set it with (set! (expander:child self) value).

Property: expander:expanded self

Whether the expander has been opened to reveal the child.

Its value is a boolean.

Set it with (set! (expander:expanded self) value).

Property: expander:label self

The text of the expanders label.

Its value is a string, or #f.

Set it with (set! (expander:label self) value).

Property: expander:label-widget self

A widget to display instead of the usual expander label.

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

Set it with (set! (expander:label-widget self) value).

Property: expander:resize-toplevel self

When this property is #t, the expander will resize the toplevel widget containing the expander upon expanding and collapsing.

Its value is a boolean.

Set it with (set! (expander:resize-toplevel self) value).

Property: expander:use-markup self

Whether the text in the label is Pango markup.

Its value is a boolean.

Set it with (set! (expander:use-markup self) value).

Property: expander:use-underline self

Whether an underline in the text indicates a mnemonic.

Its value is a boolean.

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

Procedures

Method: expander:get-child self ⇒ %return
Method: get-child self ⇒ %return

Gets the child widget of self.

self

Passed: a <GtkExpander>.

a <GtkExpander>

%return

Returned: a <GtkWidget>, or #f.

the child widget of self

Method: expander:get-expanded? self ⇒ %return
Method: get-expanded? self ⇒ %return

Queries a <GtkExpander> and returns its current state.

Returns #t if the child widget is revealed.

self

Passed: a <GtkExpander>.

a <GtkExpander>

%return

Returned: a boolean.

the current state of the expander

Method: expander:get-label self ⇒ %return
Method: get-label self ⇒ %return

Fetches the text from a label widget.

This is including any embedded underlines indicating mnemonics and Pango markup, as set by expander:set-label. If the label text has not been set the return value will be #f. This will be the case if you create an empty button with button:new to use as a container.

self

Passed: a <GtkExpander>.

a <GtkExpander>

%return

Returned: a string, or #f.

The text of the label widget. This string is owned by the widget and must not be modified or freed.

Method: expander:get-label-widget self ⇒ %return
Method: get-label-widget self ⇒ %return

Retrieves the label widget for the frame.

self

Passed: a <GtkExpander>.

a <GtkExpander>

%return

Returned: a <GtkWidget>, or #f.

the label widget

Method: expander:get-resize-toplevel? self ⇒ %return
Method: get-resize-toplevel? self ⇒ %return

Returns whether the expander will resize the toplevel widget containing the expander upon resizing and collapsing.

self

Passed: a <GtkExpander>.

a <GtkExpander>

%return

Returned: a boolean.

the “resize toplevel” setting.

Method: expander:get-use-markup? self ⇒ %return
Method: get-use-markup? self ⇒ %return

Returns whether the label’s text is interpreted as Pango markup.

self

Passed: a <GtkExpander>.

a <GtkExpander>

%return

Returned: a boolean.

#t if the label’s text will be parsed for markup

Method: expander:get-use-underline? self ⇒ %return
Method: get-use-underline? self ⇒ %return

Returns whether an underline in the text indicates a mnemonic.

self

Passed: a <GtkExpander>.

a <GtkExpander>

%return

Returned: a boolean.

#t if an embedded underline in the expander label indicates the mnemonic accelerator keys

Procedure: expander:new [label] ⇒ %return

Creates a new expander using label as the text of the label.

label

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

the text of the label

%return

Returned: a <GtkWidget>.

a new <GtkExpander> widget.

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

Creates a new expander using label as the text of the label.

If characters in label are preceded by an underscore, they are underlined. If you need a literal underscore character in a label, use “__” (two underscores). The first underlined character represents a keyboard accelerator called a mnemonic.

Pressing Alt and that key activates the button.

label

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

the text of the label with an underscore in front of the mnemonic character

%return

Returned: a <GtkWidget>.

a new <GtkExpander> widget.

Method: expander:set-child self [child]
Method: set-child self [child]

Sets the child widget of self.

self

Passed: a <GtkExpander>.

a <GtkExpander>

child

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

the child widget

Method: expander:set-expanded self expanded
Method: set-expanded self expanded

Sets the state of the expander.

Set to #t, if you want the child widget to be revealed, and #f if you want the child widget to be hidden.

self

Passed: a <GtkExpander>.

a <GtkExpander>

expanded

Passed: a boolean.

whether the child widget is revealed

Method: expander:set-label self [label]
Method: set-label self [label]

Sets the text of the label of the expander to label.

This will also clear any previously set labels.

self

Passed: a <GtkExpander>.

a <GtkExpander>

label

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

a string

Method: expander:set-label-widget self [label-widget]
Method: set-label-widget self [label-widget]

Set the label widget for the expander.

This is the widget that will appear embedded alongside the expander arrow.

self

Passed: a <GtkExpander>.

a <GtkExpander>

label-widget

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

the new label widget

Method: expander:set-resize-toplevel self resize-toplevel
Method: set-resize-toplevel self resize-toplevel

Sets whether the expander will resize the toplevel widget containing the expander upon resizing and collapsing.

self

Passed: a <GtkExpander>.

a <GtkExpander>

resize-toplevel

Passed: a boolean.

whether to resize the toplevel

Method: expander:set-use-markup self use-markup
Method: set-use-markup self use-markup

Sets whether the text of the label contains Pango markup.

self

Passed: a <GtkExpander>.

a <GtkExpander>

use-markup

Passed: a boolean.

#t if the label’s text should be parsed for markup

Method: expander:set-use-underline self use-underline
Method: set-use-underline self use-underline

If true, an underline in the text indicates a mnemonic.

self

Passed: a <GtkExpander>.

a <GtkExpander>

use-underline

Passed: a boolean.

#t if underlines in the text indicate mnemonics

Signals

Signal: expander:activate

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

Activates the <GtkExpander>.

self

Passed: a <GtkExpander>.