:right-sidebar: True Viewport =================================================================== .. currentmodule:: gi.repository.Gtk .. class:: Viewport(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.Gtk.Widget`, :class:`~gi.repository.GObject.InitiallyUnowned`, :class:`~gi.repository.GObject.Object` Implemented Interfaces: :class:`~gi.repository.Gtk.Accessible`, :class:`~gi.repository.Gtk.Buildable`, :class:`~gi.repository.Gtk.ConstraintTarget`, :class:`~gi.repository.Gtk.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 ------------ .. rst-class:: interim-class .. class:: Viewport :no-index: .. classmethod:: new(hadjustment: ~gi.repository.Gtk.Adjustment | None = None, vadjustment: ~gi.repository.Gtk.Adjustment | None = None) -> ~gi.repository.Gtk.Widget Creates a new ``GtkViewport``. The new viewport uses the given adjustments, or default adjustments if none are given. :param hadjustment: horizontal adjustment :param vadjustment: vertical adjustment Methods ------- .. rst-class:: interim-class .. class:: Viewport :no-index: .. method:: get_child() -> ~gi.repository.Gtk.Widget | None Gets the child widget of ``viewport``. .. method:: get_scroll_to_focus() -> bool Gets whether the viewport is scrolling to keep the focused child in view. .. method:: scroll_to(descendant: ~gi.repository.Gtk.Widget, scroll: ~gi.repository.Gtk.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. .. versionadded:: 4.12 :param descendant: a descendant widget of the viewport :param scroll: details of how to perform the scroll operation or NULL to scroll into view .. method:: set_child(child: ~gi.repository.Gtk.Widget | None = None) -> None Sets the child widget of ``viewport``. :param child: the child widget .. method:: set_scroll_to_focus(scroll_to_focus: bool) -> None Sets whether the viewport should automatically scroll to keep the focused child in view. :param scroll_to_focus: whether to keep the focus widget scrolled to view Properties ---------- .. rst-class:: interim-class .. class:: Viewport :no-index: .. attribute:: props.child :type: ~gi.repository.Gtk.Widget The child widget. .. attribute:: props.scroll_to_focus :type: bool 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.