`GtkExpander` allows the user to reveal its child by clicking on an expander triangle.
![An example GtkExpander](expander.png)
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 [[email protected]_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
[[email protected]:expanded[ property which can be used to monitor its expansion state. You should watch this property with a signal
connection as follows:
```c 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:
```xml <object class="GtkExpander"> <child type="label"> <object class="GtkLabel" id="expander-label"/> </child
> <child> <object class="GtkEntry" id="expander-content"/> </child> </object> ```
CSS nodes
``` 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 GtkExpander:checked
pseudoclass added to it.
Accessibility
`GtkExpander` uses the gtk_accessible_role_button role.
- public unowned Widget? get_child ()
Gets the child widget of this.
- public bool get_expanded ()
Queries a `GtkExpander` and returns its current state.
- public unowned string? get_label ()
Fetches the text from a label widget.
- public unowned Widget? get_label_widget ()
Retrieves the label widget for the frame.
- public bool get_resize_toplevel ()
Returns whether the expander will resize the toplevel widget
containing the expander upon resizing and collpasing.
- public bool get_use_markup ()
Returns whether the label’s text is interpreted as Pango markup.
- public bool get_use_underline ()
Returns whether an underline in the text indicates a mnemonic.
- public void set_child (Widget? child)
Sets the child widget of this.
- public void set_expanded (bool expanded)
Sets the state of the expander.
- public void set_label (string? label)
Sets the text of the label of the expander to label
.
- public void set_label_widget (Widget? label_widget)
Set the label widget for the expander.
- public void set_resize_toplevel (bool resize_toplevel)
Sets whether the expander will resize the toplevel widget containing
the expander upon resizing and collpasing.
- public void set_use_markup (bool use_markup)
Sets whether the text of the label contains Pango markup.
- public void set_use_underline (bool use_underline)
If true, an underline in the text indicates a mnemonic.