ViewStack

class ViewStack(**properties: Any)

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

class ViewStack
classmethod new() Widget

Creates a new AdwViewStack.

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. The title will be used by ViewSwitcher to represent child, 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. The title and icon_name will be used by ViewSwitcher to represent child.

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 in self.

Parameters:

name – the name of the child to find

get_hhomogeneous() bool

Gets whether self is horizontally homogeneous.

get_page(child: Widget) ViewStackPage

Gets the ViewStackPage object for child.

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.

get_vhomogeneous() bool

Gets whether self is vertically homogeneous.

get_visible_child() Widget | None

Gets the currently visible child of self, .

get_visible_child_name() str | None

Returns the name of the currently visible child of self.

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 of self.

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.hhomogeneous: bool

Whether the stack is horizontally homogeneous.

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.

props.pages: SelectionModel

A selection model with the stack’s pages.

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.

props.vhomogeneous: bool

Whether the stack is vertically homogeneous.

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.

props.visible_child: Widget

The widget currently visible in the stack.

props.visible_child_name: str

The name of the widget currently visible in the stack.

See visible_child.