Gtk.Viewport

g 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 Gtk.Scrollable Gtk.Scrollable GObject.GInterface->Gtk.Scrollable 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.Viewport Gtk.Viewport Gtk.Scrollable->Gtk.Viewport Gtk.Widget->Gtk.Viewport

Subclasses:

None

Methods

Inherited:

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

Structs:

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

class

new (hadjustment, vadjustment)

get_child ()

get_scroll_to_focus ()

scroll_to (descendant, scroll)

set_child (child)

set_scroll_to_focus (scroll_to_focus)

Virtual Methods

Inherited:

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

Properties

Inherited:

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

Name

Type

Flags

Short Description

child

Gtk.Widget

r/w/en

scroll-to-focus

bool

r/w/en

Signals

Inherited:

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

Fields

Inherited:

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

Class Details

class Gtk.Viewport(**kwargs)
Bases:

Gtk.Widget, Gtk.Scrollable

Abstract:

No

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.

classmethod new(hadjustment, vadjustment)[source]
Parameters:
Returns:

a new GtkViewport

Return type:

Gtk.Widget

Creates a new GtkViewport.

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

get_child()[source]
Returns:

the child widget of self

Return type:

Gtk.Widget or None

Gets the child widget of self.

get_scroll_to_focus()[source]
Returns:

True if the viewport keeps the focus child scrolled to view

Return type:

bool

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

scroll_to(descendant, scroll)[source]
Parameters:
  • descendant (Gtk.Widget) – a descendant widget of the viewport

  • scroll (Gtk.ScrollInfo or None) – details of how to perform the scroll operation or None to scroll into view

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.

New in version 4.12.

set_child(child)[source]
Parameters:

child (Gtk.Widget or None) – the child widget

Sets the child widget of self.

set_scroll_to_focus(scroll_to_focus)[source]
Parameters:

scroll_to_focus (bool) – whether to keep the focus widget scrolled to view

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

Property Details

Gtk.Viewport.props.child
Name:

child

Type:

Gtk.Widget

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The child widget.

Gtk.Viewport.props.scroll_to_focus
Name:

scroll-to-focus

Type:

bool

Default Value:

True

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Whether to scroll when the focus changes.

Before 4.6.2, this property was mistakenly defaulting to False, so if your code needs to work with older versions, consider setting it explicitly to True.