GtkExpander

GtkExpander — A container which can hide its child

Properties

GtkWidget * child Read / Write
gboolean expanded Read / Write / Construct
char * label Read / Write / Construct
GtkWidget * label-widget Read / Write
gboolean resize-toplevel Read / Write
gboolean use-markup Read / Write / Construct
gboolean use-underline Read / Write / Construct

Signals

void activate Action

Types and Values

Object Hierarchy

    GObject
    ╰── GInitiallyUnowned
        ╰── GtkWidget
            ╰── GtkExpander

Implemented Interfaces

GtkExpander implements GtkAccessible, GtkBuildable and GtkConstraintTarget.

Includes

#include <gtk/gtk.h>

Description

A GtkExpander allows the user to hide or show its child by clicking on an expander triangle 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 gtk_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 “expanded” property which can be used to monitor its expansion state. You should watch this property with a signal connection as follows:

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
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

The GtkExpander implementation of the GtkBuildable interface supports placing a child in the label position by specifying “label” as the “type” attribute of a <child> element. A normal content child can be specified without specifying a <child> type attribute.

An example of a UI definition fragment with GtkExpander:

1
2
3
4
5
6
7
8
<object class="GtkExpander">
  <child type="label">
    <object class="GtkLabel" id="expander-label"/>
  </child>
  <child>
    <object class="GtkEntry" id="expander-content"/>
  </child>
</object>


CSS nodes

1
2
3
4
5
6
expander
╰── box
    ├── title
       ├── arrow
       ╰── <label widget>
    ╰── <child>

GtkExpander has three CSS nodes, the main node with the name expander, a subnode with name title and node below it with name arrow. The arrow of an expander that is showing its child gets the :checked pseudoclass added to it.


Accessibility

GtkExpander uses the GTK_ACCESSIBLE_ROLE_BUTTON role.

Functions

gtk_expander_new ()

GtkWidget *
gtk_expander_new (const char *label);

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

Parameters

label

the text of the label.

[nullable]

Returns

a new GtkExpander widget.


gtk_expander_new_with_mnemonic ()

GtkWidget *
gtk_expander_new_with_mnemonic (const char *label);

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.

Parameters

label

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

[nullable]

Returns

a new GtkExpander widget.


gtk_expander_set_expanded ()

void
gtk_expander_set_expanded (GtkExpander *expander,
                           gboolean expanded);

Sets the state of the expander. Set to TRUE, if you want the child widget to be revealed, and FALSE if you want the child widget to be hidden.

Parameters

expander

a GtkExpander

 

expanded

whether the child widget is revealed

 

gtk_expander_get_expanded ()

gboolean
gtk_expander_get_expanded (GtkExpander *expander);

Queries a GtkExpander and returns its current state. Returns TRUE if the child widget is revealed.

See gtk_expander_set_expanded().

Parameters

expander

a GtkExpander

 

Returns

the current state of the expander


gtk_expander_set_label ()

void
gtk_expander_set_label (GtkExpander *expander,
                        const char *label);

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

This will also clear any previously set labels.

Parameters

expander

a GtkExpander

 

label

a string.

[nullable]

gtk_expander_get_label ()

const char *
gtk_expander_get_label (GtkExpander *expander);

Fetches the text from a label widget including any embedded underlines indicating mnemonics and Pango markup, as set by gtk_expander_set_label(). If the label text has not been set the return value will be NULL. This will be the case if you create an empty button with gtk_button_new() to use as a container.

Note that this function behaved differently in versions prior to 2.14 and used to return the label text stripped of embedded underlines indicating mnemonics and Pango markup. This problem can be avoided by fetching the label text directly from the label widget.

Parameters

expander

a GtkExpander

 

Returns

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

[nullable]


gtk_expander_set_use_underline ()

void
gtk_expander_set_use_underline (GtkExpander *expander,
                                gboolean use_underline);

If true, an underline in the text of the expander label indicates the next character should be used for the mnemonic accelerator key.

Parameters

expander

a GtkExpander

 

use_underline

TRUE if underlines in the text indicate mnemonics

 

gtk_expander_get_use_underline ()

gboolean
gtk_expander_get_use_underline (GtkExpander *expander);

Returns whether an embedded underline in the expander label indicates a mnemonic. See gtk_expander_set_use_underline().

Parameters

expander

a GtkExpander

 

Returns

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


gtk_expander_set_use_markup ()

void
gtk_expander_set_use_markup (GtkExpander *expander,
                             gboolean use_markup);

Sets whether the text of the label contains markup in Pango’s text markup language. See gtk_label_set_markup().

Parameters

expander

a GtkExpander

 

use_markup

TRUE if the label’s text should be parsed for markup

 

gtk_expander_get_use_markup ()

gboolean
gtk_expander_get_use_markup (GtkExpander *expander);

Returns whether the label’s text is interpreted as marked up with the Pango text markup language. See gtk_expander_set_use_markup().

Parameters

expander

a GtkExpander

 

Returns

TRUE if the label’s text will be parsed for markup


gtk_expander_set_label_widget ()

void
gtk_expander_set_label_widget (GtkExpander *expander,
                               GtkWidget *label_widget);

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

Parameters

expander

a GtkExpander

 

label_widget

the new label widget.

[nullable]

gtk_expander_get_label_widget ()

GtkWidget *
gtk_expander_get_label_widget (GtkExpander *expander);

Retrieves the label widget for the frame. See gtk_expander_set_label_widget().

Parameters

expander

a GtkExpander

 

Returns

the label widget, or NULL if there is none.

[nullable][transfer none]


gtk_expander_set_resize_toplevel ()

void
gtk_expander_set_resize_toplevel (GtkExpander *expander,
                                  gboolean resize_toplevel);

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

Parameters

expander

a GtkExpander

 

resize_toplevel

whether to resize the toplevel

 

gtk_expander_get_resize_toplevel ()

gboolean
gtk_expander_get_resize_toplevel (GtkExpander *expander);

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

Parameters

expander

a GtkExpander

 

Returns

the “resize toplevel” setting.


gtk_expander_set_child ()

void
gtk_expander_set_child (GtkExpander *expander,
                        GtkWidget *child);

Sets the child widget of expander .

Parameters

expander

a GtkExpander

 

child

the child widget.

[allow-none]

gtk_expander_get_child ()

GtkWidget *
gtk_expander_get_child (GtkExpander *expander);

Gets the child widget of expander .

Parameters

expander

a GtkExpander

 

Returns

the child widget of expander .

[nullable][transfer none]

Types and Values

GtkExpander

typedef struct _GtkExpander GtkExpander;

Property Details

The “child” property

  “child”                    GtkWidget *

The child widget.

Owner: GtkExpander

Flags: Read / Write


The “expanded” property

  “expanded”                 gboolean

Whether the expander has been opened to reveal the child widget.

Owner: GtkExpander

Flags: Read / Write / Construct

Default value: FALSE


The “label” property

  “label”                    char *

Text of the expander’s label.

Owner: GtkExpander

Flags: Read / Write / Construct

Default value: NULL


The “label-widget” property

  “label-widget”             GtkWidget *

A widget to display in place of the usual expander label.

Owner: GtkExpander

Flags: Read / Write


The “resize-toplevel” property

  “resize-toplevel”          gboolean

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

Owner: GtkExpander

Flags: Read / Write

Default value: FALSE


The “use-markup” property

  “use-markup”               gboolean

The text of the label includes XML markup. See pango_parse_markup().

Owner: GtkExpander

Flags: Read / Write / Construct

Default value: FALSE


The “use-underline” property

  “use-underline”            gboolean

If set, an underline in the text indicates the next character should be used for the mnemonic accelerator key.

Owner: GtkExpander

Flags: Read / Write / Construct

Default value: FALSE

Signal Details

The “activate” signal

void
user_function (GtkExpander *expander,
               gpointer     user_data)

Activates the GtkExpander.

Parameters

expander

the GtkExpander that emitted the signal

 

user_data

user data set when the signal handler was connected.

 

Flags: Action