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. Thetitlewill be used byViewSwitcherto representchild, so it should be short.- Parameters:
child – the widget to add
name – the name for
childtitle – 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. Thetitleandicon_namewill be used byViewSwitcherto representchild.Added in version 1.2.
- Parameters:
child – the widget to add
name – the name for
childtitle – a human-readable title for
childicon_name – an icon name for
child
- get_child_by_name(name: str) Widget | None#
Finds the child with
nameinself.- Parameters:
name – the name of the child to find
- get_page(child: Widget) ViewStackPage#
Gets the
ViewStackPageobject forchild.- Parameters:
child – a child of
self
- get_pages() SelectionModel#
Returns a
ListModelthat contains the pages of the stack.This can be used to keep an up-to-date view. The model also implements
SelectionModeland 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
selfto 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
selfhorizontally homogeneous
- set_vhomogeneous(vhomogeneous: bool) None#
Sets
selfto 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
selfvertically homogeneous
- set_visible_child(child: Widget) None#
Makes
childthe visible child ofself.- Parameters:
child – a child of
self
- set_visible_child_name(name: str) None#
Makes the child with
namevisible.See
visible_child.- Parameters:
name – the name of the child
Properties#
- class ViewStack
-
- props.pages: SelectionModel#
The type of the None singleton.