ViewStack#
Superclasses: Widget
, InitiallyUnowned
, Object
Implemented Interfaces: Accessible
, Buildable
, ConstraintTarget
A view container for ViewSwitcher
.
AdwViewStack
is a container which only shows one page at a time.
It is typically used to hold an application’s main views.
It doesn’t provide a way to transition between pages.
Instead, a separate widget such as ViewSwitcher
can be used with
AdwViewStack
to provide this functionality.
AdwViewStack
pages can have a title, an icon, an attention request, and a
numbered badge that ViewSwitcher
will use to let users identify which
page is which. Set them using the title
,
icon_name
,
needs_attention
, and
badge_number
properties.
Unlike Stack
, transitions between views are not animated.
AdwViewStack
maintains a ViewStackPage
object for each added child,
which holds additional per-child properties. You obtain the
ViewStackPage
for a child with get_page
and you
can obtain a SelectionModel
containing all the pages with
get_pages
.
AdwViewStack as GtkBuildable#
To set child-specific properties in a .ui file, create
ViewStackPage
objects explicitly, and set the child widget as a
property on it:
<object class="AdwViewStack" id="stack">
<child>
<object class="AdwViewStackPage">
<property name="name">overview</property>
<property name="title">Overview</property>
<property name="child">
<object class="AdwStatusPage">
<property name="title">Welcome!</property>
</object>
</property>
</object>
</child>
</object>
CSS nodes#
AdwViewStack
has a single CSS node named stack
.
Accessibility#
AdwViewStack
uses the GTK_ACCESSIBLE_ROLE_TAB_PANEL
for the stack pages
which are the accessible parent objects of the child widgets.
Constructors#
Methods#
- class ViewStack
- add(child: Widget) ViewStackPage #
Adds a child to
self
.- Parameters:
child – the widget to add
- add_named(child: Widget, name: str | None = None) ViewStackPage #
Adds a child to
self
.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) ViewStackPage #
Adds a child to
self
.The child is identified by the
name
. Thetitle
will be used byViewSwitcher
to representchild
, so it should be short.- Parameters:
child – the widget to add
name – the name for
child
title – a human-readable title for
child
- add_titled_with_icon(child: Widget, name: str | None, title: str, icon_name: str) ViewStackPage #
Adds a child to
self
.The child is identified by the
name
. Thetitle
andicon_name
will be used byViewSwitcher
to representchild
.Added in version 1.2.
- Parameters:
child – the widget to add
name – the name for
child
title – a human-readable title for
child
icon_name – an icon name for
child
- get_child_by_name(name: str) Widget | None #
Finds the child with
name
inself
.- Parameters:
name – the name of the child to find
- get_page(child: Widget) ViewStackPage #
Gets the
ViewStackPage
object forchild
.- Parameters:
child – a child of
self
- get_pages() SelectionModel #
Returns a
ListModel
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 change the visible page.
- remove(child: Widget) None #
Removes a child widget from
self
.- Parameters:
child – the child to remove
- set_hhomogeneous(hhomogeneous: bool) None #
Sets
self
to be horizontally homogeneous or not.If the stack is horizontally homogeneous, it allocates the same width for all children.
If it’s
FALSE
, the stack may change width when a different child becomes visible.- Parameters:
hhomogeneous – whether to make
self
horizontally homogeneous
- set_vhomogeneous(vhomogeneous: bool) None #
Sets
self
to be vertically homogeneous or not.If the stack is vertically homogeneous, it allocates the same height for all children.
If it’s
FALSE
, the stack may change height when a different child becomes visible.- Parameters:
vhomogeneous – whether to make
self
vertically homogeneous
- set_visible_child(child: Widget) None #
Makes
child
the visible child ofself
.- Parameters:
child – a child of
self
- set_visible_child_name(name: str) None #
Makes the child with
name
visible.See
visible_child
.- Parameters:
name – the name of the child
Properties#
- class ViewStack
-
- props.pages: SelectionModel#
The type of the None singleton.