Stack
Superclasses: Widget
, InitiallyUnowned
, Object
Implemented Interfaces: Accessible
, Buildable
, ConstraintTarget
GtkStack
is a container which only shows one of its children
at a time.
In contrast to GtkNotebook
, GtkStack
does not provide a means
for users to change the visible child. Instead, a separate widget
such as StackSwitcher
or StackSidebar
can
be used with GtkStack
to provide this functionality.
Transitions between pages can be animated as slides or fades. This
can be controlled with set_transition_type
.
These animations respect the gtk_enable_animations
setting.
GtkStack
maintains a StackPage
object for each added
child, which holds additional per-child properties. You
obtain the GtkStackPage
for a child with get_page
and you can obtain a GtkSelectionModel
containing all the pages
with get_pages
.
GtkStack as GtkBuildable
To set child-specific properties in a .ui file, create GtkStackPage
objects explicitly, and set the child widget as a property on it:
<object class="GtkStack" id="stack">
<child>
<object class="GtkStackPage">
<property name="name">page1</property>
<property name="title">In the beginning…</property>
<property name="child">
<object class="GtkLabel">
<property name="label">It was dark</property>
</object>
</property>
</object>
</child>
CSS nodes
GtkStack
has a single CSS node named stack.
Accessibility
GtkStack
uses the TAB_PANEL
for the stack
pages, which are the accessible parent objects of the child widgets.
Constructors
Methods
- class Stack
-
- add_named(child: Widget, name: str | None = None) StackPage
Adds a child to
stack
.The child is identified by the
name
.- Parameters:
child – the widget to add
name – the name for
child
- add_titled(child: Widget, name: str | None, title: str) StackPage
Adds a child to
stack
.The child is identified by the
name
. Thetitle
will be used byGtkStackSwitcher
to representchild
in a tab bar, so it should be short.- Parameters:
child – the widget to add
name – the name for
child
title – a human-readable title for
child
- get_child_by_name(name: str) Widget | None
Finds the child with the name given as the argument.
Returns
None
if there is no child with this name.- Parameters:
name – the name of the child to find
- get_interpolate_size() bool
Returns whether the
GtkStack
is set up to interpolate between the sizes of children on page switch.
- get_page(child: Widget) StackPage
Returns the
GtkStackPage
object forchild
.- Parameters:
child – a child of
stack
- get_pages() SelectionModel
Returns a
GListModel
that contains the pages of the stack.This can be used to keep an up-to-date view. The model also implements
SelectionModel
and can be used to track and modify the visible page.
- get_transition_duration() int
Returns the amount of time (in milliseconds) that transitions between pages in
stack
will take.
- get_transition_running() bool
Returns whether the
stack
is currently in a transition from one page to another.
- get_transition_type() StackTransitionType
Gets the type of animation that will be used for transitions between pages in
stack
.
- get_visible_child() Widget | None
Gets the currently visible child of
stack
.Returns
None
if there are no visible children.
- get_visible_child_name() str | None
Returns the name of the currently visible child of
stack
.Returns
None
if there is no visible child.
- remove(child: Widget) None
Removes a child widget from
stack
.- Parameters:
child – the child to remove
- set_hhomogeneous(hhomogeneous: bool) None
Sets the
GtkStack
to be horizontally homogeneous or not.If it is homogeneous, the
GtkStack
will request the same width for all its children. If it isn’t, the stack may change width when a different child becomes visible.- Parameters:
hhomogeneous –
True
to makestack
horizontally homogeneous
- set_interpolate_size(interpolate_size: bool) None
Sets whether or not
stack
will interpolate its size when changing the visible child.If the
interpolate_size
property is set toTrue
,stack
will interpolate its size between the current one and the one it’ll take after changing the visible child, according to the set transition duration.- Parameters:
interpolate_size – the new value
- set_transition_duration(duration: int) None
Sets the duration that transitions between pages in
stack
will take.- Parameters:
duration – the new duration, in milliseconds
- set_transition_type(transition: StackTransitionType) None
Sets the type of animation that will be used for transitions between pages in
stack
.Available types include various kinds of fades and slides.
The transition type can be changed without problems at runtime, so it is possible to change the animation based on the page that is about to become current.
- Parameters:
transition – the new transition type
- set_vhomogeneous(vhomogeneous: bool) None
Sets the
GtkStack
to be vertically homogeneous or not.If it is homogeneous, the
GtkStack
will request the same height for all its children. If it isn’t, the stack may change height when a different child becomes visible.- Parameters:
vhomogeneous –
True
to makestack
vertically homogeneous
- set_visible_child(child: Widget) None
Makes
child
the visible child ofstack
.If
child
is different from the currently visible child, the transition between the two will be animated with the current transition type ofstack
.Note that the
child
widget has to be visible itself (seeshow
) in order to become the visible child ofstack
.- Parameters:
child – a child of
stack
- set_visible_child_full(name: str, transition: StackTransitionType) None
Makes the child with the given name visible.
Note that the child widget has to be visible itself (see
show
) in order to become the visible child ofstack
.- Parameters:
name – the name of the child to make visible
transition – the transition type to use
- set_visible_child_name(name: str) None
Makes the child with the given name visible.
If
child
is different from the currently visible child, the transition between the two will be animated with the current transition type ofstack
.Note that the child widget has to be visible itself (see
show
) in order to become the visible child ofstack
.- Parameters:
name – the name of the child to make visible
Properties
- class Stack
-
- props.pages: SelectionModel
A selection model with the stack pages.
- props.transition_type: StackTransitionType
The type of animation used to transition.