Adw.ViewStack

g Adw.ViewStack Adw.ViewStack GObject.GInterface GObject.GInterface Gtk.Accessible Gtk.Accessible GObject.GInterface->Gtk.Accessible Gtk.Buildable Gtk.Buildable GObject.GInterface->Gtk.Buildable Gtk.ConstraintTarget Gtk.ConstraintTarget GObject.GInterface->Gtk.ConstraintTarget GObject.InitiallyUnowned GObject.InitiallyUnowned Gtk.Widget Gtk.Widget GObject.InitiallyUnowned->Gtk.Widget GObject.Object GObject.Object GObject.Object->GObject.InitiallyUnowned Gtk.Accessible->Gtk.Widget Gtk.Buildable->Gtk.Widget Gtk.ConstraintTarget->Gtk.Widget Gtk.Widget->Adw.ViewStack

Subclasses:

None

Methods

Inherited:

Gtk.Widget (181), GObject.Object (37), Gtk.Accessible (15), Gtk.Buildable (1)

Structs:

Gtk.WidgetClass (18), GObject.ObjectClass (5)

class

new ()

add (child)

add_named (child, name)

add_titled (child, name, title)

add_titled_with_icon (child, name, title, icon_name)

get_child_by_name (name)

get_hhomogeneous ()

get_page (child)

get_pages ()

get_vhomogeneous ()

get_visible_child ()

get_visible_child_name ()

remove (child)

set_hhomogeneous (hhomogeneous)

set_vhomogeneous (vhomogeneous)

set_visible_child (child)

set_visible_child_name (name)

Virtual Methods

Inherited:

Gtk.Widget (25), GObject.Object (7), Gtk.Accessible (6), Gtk.Buildable (9)

Properties

Inherited:

Gtk.Widget (34), Gtk.Accessible (1)

Name

Type

Flags

Short Description

hhomogeneous

bool

r/w/en

pages

Gtk.SelectionModel

r

vhomogeneous

bool

r/w/en

visible-child

Gtk.Widget

r/w/en

visible-child-name

str

r/w/en

Signals

Inherited:

Gtk.Widget (13), GObject.Object (1)

Fields

Inherited:

Gtk.Widget (13), GObject.Object (1)

Class Details

class Adw.ViewStack(**kwargs)
Bases:

Gtk.Widget

Abstract:

No

Structure:

Adw.ViewStackClass

A view container for [class`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 [class`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 [class`ViewSwitcher`] will use to let users identify which page is which. Set them using the [property`ViewStackPage`:py:data::title<Adw.ViewStack.props.title>], [property`ViewStackPage`:py:data::icon-name<Adw.ViewStack.props.icon_name>], [property`ViewStackPage`:py:data::needs-attention<Adw.ViewStack.props.needs_attention>], and [property`ViewStackPage`:py:data::badge-number<Adw.ViewStack.props.badge_number>] properties.

Unlike [class`Gtk`.Stack], transitions between views are not animated.

AdwViewStack maintains a [class`ViewStackPage`] object for each added child, which holds additional per-child properties. You obtain the [class`ViewStackPage`] for a child with [method`ViewStack`.get_page] and you can obtain a [iface`Gtk`.SelectionModel] containing all the pages with [method`ViewStack`.get_pages].

Adw.ViewStack as Gtk.Buildable

To set child-specific properties in a .ui file, create [class`ViewStackPage`] objects explicitly, and set the child widget as a property on it:

```xml

<child>

overview Overview

Welcome! </object>

/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.

classmethod new()
Returns:

the newly created AdwViewStack

Return type:

Gtk.Widget

Creates a new AdwViewStack.

add(child)
Parameters:

child (Gtk.Widget) – the widget to add

Returns:

the [class`ViewStackPage`] for child

Return type:

Adw.ViewStackPage

Adds a child to self.

add_named(child, name)
Parameters:
Returns:

the AdwViewStackPage for child

Return type:

Adw.ViewStackPage

Adds a child to self.

The child is identified by the name.

add_titled(child, name, title)
Parameters:
  • child (Gtk.Widget) – the widget to add

  • name (str or None) – the name for child

  • title (str) – a human-readable title for child

Returns:

the AdwViewStackPage for child

Return type:

Adw.ViewStackPage

Adds a child to self.

The child is identified by the name. The title will be used by [class`ViewSwitcher`] to represent child, so it should be short.

add_titled_with_icon(child, name, title, icon_name)
Parameters:
  • child (Gtk.Widget) – the widget to add

  • name (str or None) – the name for child

  • title (str) – a human-readable title for child

  • icon_name (str) – an icon name for child

Returns:

the AdwViewStackPage for child

Return type:

Adw.ViewStackPage

Adds a child to self.

The child is identified by the name. The title and icon_name will be used by [class`ViewSwitcher`] to represent child.

New in version 1.2.

get_child_by_name(name)
Parameters:

name (str) – the name of the child to find

Returns:

the requested child

Return type:

Gtk.Widget or None

Finds the child with name in self.

get_hhomogeneous()
Returns:

whether self is horizontally homogeneous

Return type:

bool

Gets whether self is horizontally homogeneous.

get_page(child)
Parameters:

child (Gtk.Widget) – a child of self

Returns:

the page object for child

Return type:

Adw.ViewStackPage

Gets the [class`ViewStackPage`] object for child.

get_pages()
Returns:

a GtkSelectionModel for the stack’s children

Return type:

Gtk.SelectionModel

Returns a [iface`Gio`.ListModel] that contains the pages of the stack.

This can be used to keep an up-to-date view. The model also implements [iface`Gtk`.SelectionModel] and can be used to track and change the visible page.

get_vhomogeneous()
Returns:

whether self is vertically homogeneous

Return type:

bool

Gets whether self is vertically homogeneous.

get_visible_child()
Returns:

the visible child

Return type:

Gtk.Widget or None

Gets the currently visible child of self.

get_visible_child_name()
Returns:

the name of the visible child

Return type:

str or None

Returns the name of the currently visible child of self.

remove(child)
Parameters:

child (Gtk.Widget) – the child to remove

Removes a child widget from self.

set_hhomogeneous(hhomogeneous)
Parameters:

hhomogeneous (bool) – whether to make self horizontally homogeneous

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.

set_vhomogeneous(vhomogeneous)
Parameters:

vhomogeneous (bool) – whether to make self vertically homogeneous

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.

set_visible_child(child)
Parameters:

child (Gtk.Widget) – a child of self

Makes child the visible child of self.

set_visible_child_name(name)
Parameters:

name (str) – the name of the child

Makes the child with name visible.

See [property`ViewStack`:py:data::visible-child<Adw.ViewStack.props.visible_child>].

Property Details

Adw.ViewStack.props.hhomogeneous
Name:

hhomogeneous

Type:

bool

Default Value:

True

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

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.

Adw.ViewStack.props.pages
Name:

pages

Type:

Gtk.SelectionModel

Default Value:

None

Flags:

READABLE

A selection model with the stack’s pages.

This can be used to keep an up-to-date view. The model also implements [iface`Gtk`.SelectionModel] and can be used to track and change the visible page.

Adw.ViewStack.props.vhomogeneous
Name:

vhomogeneous

Type:

bool

Default Value:

True

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

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.

Adw.ViewStack.props.visible_child
Name:

visible-child

Type:

Gtk.Widget

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The widget currently visible in the stack.

Adw.ViewStack.props.visible_child_name
Name:

visible-child-name

Type:

str

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The name of the widget currently visible in the stack.

See [property`ViewStack`:py:data::visible-child<Adw.ViewStack.props.visible_child>].