Skip to content

Gtk.Scrollable

interface

An interface for widgets with native scrolling ability.

To implement this interface you should override the Scrollable.hadjustment and Scrollable.vadjustment properties.

Creating a scrollable widget

All scrollable widgets should do the following.

  • When a parent widget sets the scrollable child widget’s adjustments, the widget should connect to the Adjustment.value-changed signal. The child widget should then populate the adjustments’ properties as soon as possible, which usually means queueing an allocation right away and populating the properties in the Widget.size_allocate implementation.

  • Because its preferred size is the size for a fully expanded widget, the scrollable widget must be able to cope with underallocations. This means that it must accept any value passed to its Widget.size_allocate implementation.

  • When the parent allocates space to the scrollable child widget, the widget must ensure the adjustments’ property values are correct and up to date, for example using Adjustment.configure.

  • When any of the adjustments emits the Adjustment.value-changed signal, the scrollable widget should scroll its contents.

Methods

get_border

def get_border(self) -> tuple[bool, Border]

Returns the size of a non-scrolling border around the outside of the scrollable.

An example for this would be treeview headers. GTK can use this information to display overlaid graphics, like the overshoot indication, at the right position.

get_hadjustment

def get_hadjustment(self) -> Adjustment | None

Retrieves the GtkAdjustment used for horizontal scrolling.

get_hscroll_policy

def get_hscroll_policy(self) -> ScrollablePolicy

Gets the horizontal GtkScrollablePolicy.

get_vadjustment

def get_vadjustment(self) -> Adjustment | None

Retrieves the GtkAdjustment used for vertical scrolling.

get_vscroll_policy

def get_vscroll_policy(self) -> ScrollablePolicy

Gets the vertical GtkScrollablePolicy.

set_hadjustment

def set_hadjustment(self, hadjustment: Adjustment | None = ...) -> None

Sets the horizontal adjustment of the GtkScrollable.

Parameters:

  • hadjustment — a GtkAdjustment

set_hscroll_policy

def set_hscroll_policy(self, policy: ScrollablePolicy | int) -> None

Sets the GtkScrollablePolicy.

The policy determines whether horizontal scrolling should start below the minimum width or below the natural width.

Parameters:

  • policy — the horizontal GtkScrollablePolicy

set_vadjustment

def set_vadjustment(self, vadjustment: Adjustment | None = ...) -> None

Sets the vertical adjustment of the GtkScrollable.

Parameters:

  • vadjustment — a GtkAdjustment

set_vscroll_policy

def set_vscroll_policy(self, policy: ScrollablePolicy | int) -> None

Sets the GtkScrollablePolicy.

The policy determines whether vertical scrolling should start below the minimum height or below the natural height.

Parameters:

  • policy — the vertical GtkScrollablePolicy

Virtual methods

do_get_border

def do_get_border(self) -> tuple[bool, Border]

Returns the size of a non-scrolling border around the outside of the scrollable.

An example for this would be treeview headers. GTK can use this information to display overlaid graphics, like the overshoot indication, at the right position.

Properties

hadjustment

hadjustment: Adjustment  # read/write

Horizontal GtkAdjustment of the scrollable widget.

This adjustment is shared between the scrollable widget and its parent.

hscroll_policy

hscroll_policy: ScrollablePolicy | int  # read/write

Determines when horizontal scrolling should start.

vadjustment

vadjustment: Adjustment  # read/write

Vertical GtkAdjustment of the scrollable widget.

This adjustment is shared between the scrollable widget and its parent.

vscroll_policy

vscroll_policy: ScrollablePolicy | int  # read/write

Determines when vertical scrolling should start.