Class: Gtk::Expander
- Defined in:
- (unknown)
Overview
GtkExpander allows the user to reveal its child by clicking
on an expander triangle.

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 [methodGtk.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
[propertyGtk.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
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:
<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-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_ACCESSIBLE_ROLE_BUTTON role.
Instance Method Summary collapse
-
#child ⇒ Gtk::Widget
The child widget.
-
#child=(child) ⇒ Gtk::Widget
The child widget.
-
#expanded ⇒ Boolean
Queries a
GtkExpanderand returns its current state. -
#expanded=(expanded) ⇒ Boolean
Whether the expander has been opened to reveal the child.
-
#expanded? ⇒ Boolean
Whether the expander has been opened to reveal the child.
-
#initialize(label) ⇒ Gtk::Widget
constructor
Creates a new expander using label as the text of the label.
-
#label ⇒ String
The text of the expanders label.
-
#label=(label) ⇒ String
The text of the expanders label.
-
#label_widget ⇒ Gtk::Widget
A widget to display instead of the usual expander label.
-
#label_widget=(label_widget) ⇒ Gtk::Widget
A widget to display instead of the usual expander label.
-
#resize_toplevel ⇒ Boolean
Returns whether the expander will resize the toplevel widget containing the expander upon resizing and collapsing.
-
#resize_toplevel=(resize_toplevel) ⇒ Boolean
When this property is true, the expander will resize the toplevel widget containing the expander upon expanding and collapsing.
-
#resize_toplevel? ⇒ Boolean
When this property is true, the expander will resize the toplevel widget containing the expander upon expanding and collapsing.
-
#use_markup ⇒ Boolean
Returns whether the label’s text is interpreted as Pango markup.
-
#use_markup=(use_markup) ⇒ Boolean
Whether the text in the label is Pango markup.
-
#use_markup? ⇒ Boolean
Whether the text in the label is Pango markup.
-
#use_underline ⇒ Boolean
Returns whether an underline in the text indicates a mnemonic.
-
#use_underline=(use_underline) ⇒ Boolean
Whether an underline in the text indicates a mnemonic.
-
#use_underline? ⇒ Boolean
Whether an underline in the text indicates a mnemonic.
Methods inherited from Widget
#accessible_role, #accessible_role=, #action_set_enabled, #activate, #activate_action, #activate_action_variant, #activate_default, #activate_signal, #activate_signal=, #activate_signal_from_name=, #add_binding, #add_binding_action, #add_binding_signal, #add_controller, #add_css_class, #add_mnemonic_label, #add_shortcut, #add_tick_callback, #allocate, #allocated_baseline, #allocated_height, #allocated_width, #baseline, #bind_template_callback_full, #bind_template_child_full, #can_focus, #can_focus=, #can_focus?, #can_target, #can_target=, #can_target?, #child_focus, #child_visible, #child_visible=, #clipboard, #compute_bounds, #compute_expand, #compute_point, #compute_transform, #contains, #create_pango_context, #create_pango_layout, #css_classes, #css_classes=, #css_name, #css_name=, #cursor, #cursor=, #cursor_from_name=, default_direction, default_direction=, #direction, #direction=, #display, #dispose_template, #drag_check_threshold, #error_bell, #first_child, #focus_child, #focus_child=, #focus_on_click, #focus_on_click=, #focus_on_click?, #focusable, #focusable=, #focusable?, #font_map, #font_map=, #font_options, #font_options=, #frame_clock, #get_allocation, #get_ancestor, #get_color, #get_preferred_size, #get_size, #get_size_request, #get_template_child, #grab_focus, #halign, #halign=, #has_css_class, #has_default, #has_default=, #has_default?, #has_focus, #has_focus=, #has_focus?, #has_tooltip, #has_tooltip=, #has_tooltip?, #has_visible_focus, #height, #height_request, #height_request=, #hexpand, #hexpand=, #hexpand?, #hexpand_set, #hexpand_set=, #hexpand_set?, #hide, #in_destruction, #init_template, #insert_action_group, #insert_after, #insert_before, #install_action, #install_property_action, #is_ancestor, #is_drawable, #is_focus, #is_sensitive, #is_visible, #keynav_failed, #last_child, #layout_manager, #layout_manager=, #layout_manager_type, #layout_manager_type=, #list_mnemonic_labels, #map, #mapped, #margin_bottom, #margin_bottom=, #margin_end, #margin_end=, #margin_start, #margin_start=, #margin_top, #margin_top=, #measure, #mnemonic_activate, #name, #name=, #native, #next_sibling, #observe_children, #observe_controllers, #opacity, #opacity=, #overflow, #overflow=, #pango_context, #parent, #parent=, #pick, #prev_sibling, #primary_clipboard, #query_action, #queue_allocate, #queue_draw, #queue_resize, #realize, #realized, #receives_default, #receives_default=, #receives_default?, #remove_controller, #remove_css_class, #remove_mnemonic_label, #remove_tick_callback, #request_mode, #root, #root=, #scale_factor, #scale_factor=, #sensitive, #sensitive=, #sensitive?, #set_size_request, #set_state_flags, #settings, #should_layout, #show, #size_allocate, #snapshot_child, #state_flags, #style_context, #template=, #template_from_resource=, #template_scope=, #tooltip_markup, #tooltip_markup=, #tooltip_text, #tooltip_text=, #translate_coordinates, #trigger_tooltip_query, #unmap, #unparent, #unrealize, #unset_state_flags, #valign, #valign=, #vexpand, #vexpand=, #vexpand?, #vexpand_set, #vexpand_set=, #vexpand_set?, #visible, #visible=, #visible?, #width, #width_request, #width_request=
Constructor Details
#initialize(label) ⇒ Gtk::Widget
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.
Instance Method Details
#child ⇒ Gtk::Widget
The child widget.
#child=(child) ⇒ Gtk::Widget
The child widget.
#expanded ⇒ Boolean
Queries a GtkExpander and returns its current state.
Returns true if the child widget is revealed.
#expanded=(expanded) ⇒ Boolean
Whether the expander has been opened to reveal the child.
#expanded? ⇒ Boolean
Whether the expander has been opened to reveal the child.
#label ⇒ String
The text of the expanders label.
#label=(label) ⇒ String
The text of the expanders label.
#label_widget ⇒ Gtk::Widget
A widget to display instead of the usual expander label.
#label_widget=(label_widget) ⇒ Gtk::Widget
A widget to display instead of the usual expander label.
#resize_toplevel ⇒ Boolean
Returns whether the expander will resize the toplevel widget containing the expander upon resizing and collapsing.
#resize_toplevel=(resize_toplevel) ⇒ Boolean
When this property is true, the expander will resize the toplevel widget containing the expander upon expanding and collapsing.
#resize_toplevel? ⇒ Boolean
When this property is true, the expander will resize the toplevel widget containing the expander upon expanding and collapsing.
#use_markup ⇒ Boolean
Returns whether the label’s text is interpreted as Pango markup.
#use_markup=(use_markup) ⇒ Boolean
Whether the text in the label is Pango markup.
#use_markup? ⇒ Boolean
Whether the text in the label is Pango markup.
#use_underline ⇒ Boolean
Returns whether an underline in the text indicates a mnemonic.
#use_underline=(use_underline) ⇒ Boolean
Whether an underline in the text indicates a mnemonic.
#use_underline? ⇒ Boolean
Whether an underline in the text indicates a mnemonic.