Viewport#

class Viewport(**properties: Any)#

Superclasses: Widget, InitiallyUnowned, Object

Implemented Interfaces: Accessible, Buildable, ConstraintTarget, Scrollable

GtkViewport implements scrollability for widgets that lack their own scrolling capabilities.

Use GtkViewport to scroll child widgets such as GtkGrid, GtkBox, and so on.

The GtkViewport will start scrolling content only if allocated less than the child widget’s minimum size in a given orientation.

CSS nodes#

GtkViewport has a single CSS node with name viewport.

Accessibility#

Until GTK 4.10, GtkViewport used the GTK_ACCESSIBLE_ROLE_GROUP role.

Starting from GTK 4.12, GtkViewport uses the GTK_ACCESSIBLE_ROLE_GENERIC role.

Constructors#

class Viewport
classmethod new(hadjustment: Adjustment | None = None, vadjustment: Adjustment | None = None) Widget#

Creates a new GtkViewport.

The new viewport uses the given adjustments, or default adjustments if none are given.

Parameters:
  • hadjustment – horizontal adjustment

  • vadjustment – vertical adjustment

Methods#

class Viewport
get_child() Widget | None#

Gets the child widget of viewport.

get_scroll_to_focus() bool#

Gets whether the viewport is scrolling to keep the focused child in view.

scroll_to(descendant: Widget, scroll: ScrollInfo | None = None) None#

Scrolls a descendant of the viewport into view.

The viewport and the descendant must be visible and mapped for this function to work, otherwise no scrolling will be performed.

Added in version 4.12.

Parameters:
  • descendant – a descendant widget of the viewport

  • scroll – details of how to perform the scroll operation or NULL to scroll into view

set_child(child: Widget | None = None) None#

Sets the child widget of viewport.

Parameters:

child – the child widget

set_scroll_to_focus(scroll_to_focus: bool) None#

Sets whether the viewport should automatically scroll to keep the focused child in view.

Parameters:

scroll_to_focus – whether to keep the focus widget scrolled to view

Properties#

class Viewport
props.child: Widget#

The type of the None singleton.

props.scroll_to_focus: bool#

The type of the None singleton.