Gtk.Viewport¶
class — extends Widget, Accessible, Buildable, ConstraintTarget, Scrollable
Implements scrollability for widgets that don't support scrolling on their own.
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 AccessibleRole.group role.
Starting from GTK 4.12, GtkViewport uses the AccessibleRole.generic role.
Constructors¶
new¶
@classmethod
def new(cls, hadjustment: Adjustment | None = ..., vadjustment: Adjustment | None = ...) -> Widget
Creates a new GtkViewport.
The new viewport uses the given adjustments, or default adjustments if none are given.
Parameters:
hadjustment— horizontal adjustmentvadjustment— vertical adjustment
Methods¶
get_child¶
Gets the child widget of viewport.
get_scroll_to_focus¶
Gets whether the viewport is scrolling to keep the focused child in view.
scroll_to¶
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.
Parameters:
descendant— a descendant widget of the viewportscroll— details of how to perform the scroll operation or NULL to scroll into view
set_child¶
Sets the child widget of viewport.
Parameters:
child— the child widget
set_scroll_to_focus¶
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¶
child¶
The child widget.
scroll_to_focus¶
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.