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 any other descendant
of GtkBin; you create the child widget and use gtk_container_add()
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:
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:
CSS nodes
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.
Functions
gtk_expander_new ()
GtkWidget *
gtk_expander_new (const gchar *label);
Creates a new expander using label
as the text of the label.
Since: 2.4
gtk_expander_new_with_mnemonic ()
GtkWidget *
gtk_expander_new_with_mnemonic (const gchar *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.
Since: 2.4
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.
Since: 2.4
gtk_expander_set_spacing ()
void
gtk_expander_set_spacing (GtkExpander *expander,
gint spacing);
gtk_expander_set_spacing has been deprecated since version 3.20 and should not be used in newly-written code.
Use margins on the child instead.
Sets the spacing field of expander
, which is the number of
pixels to place between expander and the child.
Since: 2.4
gtk_expander_get_spacing ()
gint
gtk_expander_get_spacing (GtkExpander *expander);
gtk_expander_get_spacing has been deprecated since version 3.20 and should not be used in newly-written code.
Use margins on the child instead.
Gets the value set by gtk_expander_set_spacing().
Returns
spacing between the expander and child
Since: 2.4
gtk_expander_set_label ()
void
gtk_expander_set_label (GtkExpander *expander,
const gchar *label);
Sets the text of the label of the expander to label
.
This will also clear any previously set labels.
Since: 2.4
gtk_expander_get_label ()
const gchar *
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.
Returns
The text of the label widget. This string is owned
by the widget and must not be modified or freed.
[nullable]
Since: 2.4
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.
Since: 2.4
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().
Returns
TRUE if an embedded underline in the expander
label indicates the mnemonic accelerator keys
Since: 2.4
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().
Since: 2.4
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().
Returns
TRUE if the label’s text will be parsed for markup
Since: 2.4
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.
Since: 2.4
gtk_expander_set_label_fill ()
void
gtk_expander_set_label_fill (GtkExpander *expander,
gboolean label_fill);
Sets whether the label widget should fill all available
horizontal space allocated to expander
.
Since: 2.22
gtk_expander_get_label_fill ()
gboolean
gtk_expander_get_label_fill (GtkExpander *expander);
Returns whether the label widget will fill all available
horizontal space allocated to expander
.
Returns
TRUE if the label widget will fill all
available horizontal space
Since: 2.22
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.
Since: 3.2
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.
Returns
the “resize toplevel” setting.
Since: 3.2
Property Details
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” gchar *
Text of the expander's label.
Owner: GtkExpander
Flags: Read / Write / Construct
Default value: NULL
The “label-fill” property
“label-fill” gboolean
Whether the label widget should fill all available horizontal space.
Owner: GtkExpander
Flags: Read / Write / Construct
Default value: FALSE
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
Since: 3.2
The “spacing” property
“spacing” gint
Space to put between the label and the child when the
expander is expanded.
GtkExpander:spacing has been deprecated since version 3.20 and should not be used in newly-written code.
This property is deprecated and ignored.
Use margins on the child instead.
Owner: GtkExpander
Flags: Read / Write
Allowed values: >= 0
Default value: 0
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