:right-sidebar: True ScrolledWindow =================================================================== .. currentmodule:: gi.repository.Gtk .. class:: ScrolledWindow(**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` ``GtkScrolledWindow`` is a container that makes its child scrollable. It does so using either internally added scrollbars or externally associated adjustments, and optionally draws a frame around the child. Widgets with native scrolling support, i.e. those whose classes implement the :obj:`~gi.repository.Gtk.Scrollable` interface, are added directly. For other types of widget, the class :obj:`~gi.repository.Gtk.Viewport` acts as an adaptor, giving scrollability to other widgets. :obj:`~gi.repository.Gtk.ScrolledWindow.set_child` intelligently accounts for whether or not the added child is a ``GtkScrollable``. If it isn’t, then it wraps the child in a ``GtkViewport``. Therefore, you can just add any child widget and not worry about the details. If :obj:`~gi.repository.Gtk.ScrolledWindow.set_child` has added a ``GtkViewport`` for you, it will be automatically removed when you unset the child. Unless :obj:`~gi.repository.Gtk.ScrolledWindow.props.hscrollbar_policy` and :obj:`~gi.repository.Gtk.ScrolledWindow.props.vscrollbar_policy` are :const:`~gi.repository.Gtk.PolicyType.NEVER` or :const:`~gi.repository.Gtk.PolicyType.EXTERNAL`, ``GtkScrolledWindow`` adds internal ``GtkScrollbar`` widgets around its child. The scroll position of the child, and if applicable the scrollbars, is controlled by the :obj:`~gi.repository.Gtk.ScrolledWindow.props.hadjustment` and :obj:`~gi.repository.Gtk.ScrolledWindow.props.vadjustment` that are associated with the ``GtkScrolledWindow``. See the docs on :obj:`~gi.repository.Gtk.Scrollbar` for the details, but note that the “step_increment” and “page_increment” fields are only effective if the policy causes scrollbars to be present. If a ``GtkScrolledWindow`` doesn’t behave quite as you would like, or doesn’t have exactly the right layout, it’s very possible to set up your own scrolling with ``GtkScrollbar`` and for example a ``GtkGrid``. Touch support ------------- ``GtkScrolledWindow`` has built-in support for touch devices. When a touchscreen is used, swiping will move the scrolled window, and will expose 'kinetic' behavior. This can be turned off with the :obj:`~gi.repository.Gtk.ScrolledWindow.props.kinetic_scrolling` property if it is undesired. ``GtkScrolledWindow`` also displays visual 'overshoot' indication when the content is pulled beyond the end, and this situation can be captured with the :obj:`~gi.repository.Gtk.ScrolledWindow.signals.edge_overshot` signal. If no mouse device is present, the scrollbars will overlaid as narrow, auto-hiding indicators over the content. If traditional scrollbars are desired although no mouse is present, this behaviour can be turned off with the :obj:`~gi.repository.Gtk.ScrolledWindow.props.overlay_scrolling` property. CSS nodes --------- ``GtkScrolledWindow`` has a main CSS node with name scrolledwindow. It gets a .frame style class added when :obj:`~gi.repository.Gtk.ScrolledWindow.props.has_frame` is :const:`True`. It uses subnodes with names overshoot and undershoot to draw the overflow and underflow indications. These nodes get the .left, .right, .top or .bottom style class added depending on where the indication is drawn. ``GtkScrolledWindow`` also sets the positional style classes (.left, .right, .top, .bottom) and style classes related to overlay scrolling (.overlay-indicator, .dragging, .hovering) on its scrollbars. If both scrollbars are visible, the area where they meet is drawn with a subnode named junction. Accessibility ------------- Until GTK 4.10, ``GtkScrolledWindow`` used the ``GTK_ACCESSIBLE_ROLE_GROUP`` role. Starting from GTK 4.12, ``GtkScrolledWindow`` uses the ``GTK_ACCESSIBLE_ROLE_GENERIC`` role. Constructors ------------ .. rst-class:: interim-class .. class:: ScrolledWindow :no-index: .. classmethod:: new() -> ~gi.repository.Gtk.Widget Creates a new scrolled window. Methods ------- .. rst-class:: interim-class .. class:: ScrolledWindow :no-index: .. method:: get_child() -> ~gi.repository.Gtk.Widget | None Gets the child widget of ``scrolled_window``. If the scrolled window automatically added a :obj:`~gi.repository.Gtk.Viewport`, this function will return the viewport widget, and you can retrieve its child using :obj:`~gi.repository.Gtk.Viewport.get_child`. .. method:: get_hadjustment() -> ~gi.repository.Gtk.Adjustment Returns the horizontal scrollbar’s adjustment. This is the adjustment used to connect the horizontal scrollbar to the child widget’s horizontal scroll functionality. .. method:: get_has_frame() -> bool Gets whether the scrolled window draws a frame. .. method:: get_hscrollbar() -> ~gi.repository.Gtk.Widget Returns the horizontal scrollbar of ``scrolled_window``. .. method:: get_kinetic_scrolling() -> bool Returns the specified kinetic scrolling behavior. .. method:: get_max_content_height() -> int Returns the maximum content height set. .. method:: get_max_content_width() -> int Returns the maximum content width set. .. method:: get_min_content_height() -> int Gets the minimal content height of ``scrolled_window``. .. method:: get_min_content_width() -> int Gets the minimum content width of ``scrolled_window``. .. method:: get_overlay_scrolling() -> bool Returns whether overlay scrolling is enabled for this scrolled window. .. method:: get_placement() -> ~gi.repository.Gtk.CornerType Gets the placement of the contents with respect to the scrollbars. .. method:: get_policy() -> tuple[~gi.repository.Gtk.PolicyType, ~gi.repository.Gtk.PolicyType] Retrieves the current policy values for the horizontal and vertical scrollbars. See :obj:`~gi.repository.Gtk.ScrolledWindow.set_policy`. .. method:: get_propagate_natural_height() -> bool Reports whether the natural height of the child will be calculated and propagated through the scrolled window’s requested natural height. .. method:: get_propagate_natural_width() -> bool Reports whether the natural width of the child will be calculated and propagated through the scrolled window’s requested natural width. .. method:: get_vadjustment() -> ~gi.repository.Gtk.Adjustment Returns the vertical scrollbar’s adjustment. This is the adjustment used to connect the vertical scrollbar to the child widget’s vertical scroll functionality. .. method:: get_vscrollbar() -> ~gi.repository.Gtk.Widget Returns the vertical scrollbar of ``scrolled_window``. .. method:: set_child(child: ~gi.repository.Gtk.Widget | None = None) -> None Sets the child widget of ``scrolled_window``. If ``child`` does not implement the :obj:`~gi.repository.Gtk.Scrollable` interface, the scrolled window will add ``child`` to a :obj:`~gi.repository.Gtk.Viewport` instance and then add the viewport as its child widget. :param child: the child widget .. method:: set_hadjustment(hadjustment: ~gi.repository.Gtk.Adjustment | None = None) -> None Sets the ``GtkAdjustment`` for the horizontal scrollbar. :param hadjustment: the ``GtkAdjustment`` to use, or :const:`None` to create a new one .. method:: set_has_frame(has_frame: bool) -> None Changes the frame drawn around the contents of ``scrolled_window``. :param has_frame: whether to draw a frame around scrolled window contents .. method:: set_kinetic_scrolling(kinetic_scrolling: bool) -> None Turns kinetic scrolling on or off. Kinetic scrolling only applies to devices with source ``%GDK_SOURCE_TOUCHSCREEN``. :param kinetic_scrolling: :const:`True` to enable kinetic scrolling .. method:: set_max_content_height(height: int) -> None Sets the maximum height that ``scrolled_window`` should keep visible. The ``scrolled_window`` will grow up to this height before it starts scrolling the content. It is a programming error to set the maximum content height to a value smaller than :obj:`~gi.repository.Gtk.ScrolledWindow.props.min_content_height`. :param height: the maximum content height .. method:: set_max_content_width(width: int) -> None Sets the maximum width that ``scrolled_window`` should keep visible. The ``scrolled_window`` will grow up to this width before it starts scrolling the content. It is a programming error to set the maximum content width to a value smaller than :obj:`~gi.repository.Gtk.ScrolledWindow.props.min_content_width`. :param width: the maximum content width .. method:: set_min_content_height(height: int) -> None Sets the minimum height that ``scrolled_window`` should keep visible. Note that this can and (usually will) be smaller than the minimum size of the content. It is a programming error to set the minimum content height to a value greater than :obj:`~gi.repository.Gtk.ScrolledWindow.props.max_content_height`. :param height: the minimal content height .. method:: set_min_content_width(width: int) -> None Sets the minimum width that ``scrolled_window`` should keep visible. Note that this can and (usually will) be smaller than the minimum size of the content. It is a programming error to set the minimum content width to a value greater than :obj:`~gi.repository.Gtk.ScrolledWindow.props.max_content_width`. :param width: the minimal content width .. method:: set_overlay_scrolling(overlay_scrolling: bool) -> None Enables or disables overlay scrolling for this scrolled window. :param overlay_scrolling: whether to enable overlay scrolling .. method:: set_placement(window_placement: ~gi.repository.Gtk.CornerType) -> None Sets the placement of the contents with respect to the scrollbars for the scrolled window. The default is :const:`~gi.repository.Gtk.CornerType.TOP_LEFT`, meaning the child is in the top left, with the scrollbars underneath and to the right. Other values in :obj:`~gi.repository.Gtk.CornerType` are :const:`~gi.repository.Gtk.CornerType.TOP_RIGHT`, :const:`~gi.repository.Gtk.CornerType.BOTTOM_LEFT`, and :const:`~gi.repository.Gtk.CornerType.BOTTOM_RIGHT`. See also :obj:`~gi.repository.Gtk.ScrolledWindow.get_placement` and :obj:`~gi.repository.Gtk.ScrolledWindow.unset_placement`. :param window_placement: position of the child window .. method:: set_policy(hscrollbar_policy: ~gi.repository.Gtk.PolicyType, vscrollbar_policy: ~gi.repository.Gtk.PolicyType) -> None Sets the scrollbar policy for the horizontal and vertical scrollbars. The policy determines when the scrollbar should appear; it is a value from the :obj:`~gi.repository.Gtk.PolicyType` enumeration. If :const:`~gi.repository.Gtk.PolicyType.ALWAYS`, the scrollbar is always present; if :const:`~gi.repository.Gtk.PolicyType.NEVER`, the scrollbar is never present; if :const:`~gi.repository.Gtk.PolicyType.AUTOMATIC`, the scrollbar is present only if needed (that is, if the slider part of the bar would be smaller than the trough — the display is larger than the page size). :param hscrollbar_policy: policy for horizontal bar :param vscrollbar_policy: policy for vertical bar .. method:: set_propagate_natural_height(propagate: bool) -> None Sets whether the natural height of the child should be calculated and propagated through the scrolled window’s requested natural height. :param propagate: whether to propagate natural height .. method:: set_propagate_natural_width(propagate: bool) -> None Sets whether the natural width of the child should be calculated and propagated through the scrolled window’s requested natural width. :param propagate: whether to propagate natural width .. method:: set_vadjustment(vadjustment: ~gi.repository.Gtk.Adjustment | None = None) -> None Sets the ``GtkAdjustment`` for the vertical scrollbar. :param vadjustment: the ``GtkAdjustment`` to use, or :const:`None` to create a new one .. method:: unset_placement() -> None Unsets the placement of the contents with respect to the scrollbars. If no window placement is set for a scrolled window, it defaults to :const:`~gi.repository.Gtk.CornerType.TOP_LEFT`. Properties ---------- .. rst-class:: interim-class .. class:: ScrolledWindow :no-index: .. attribute:: props.child :type: ~gi.repository.Gtk.Widget The child widget. When setting this property, if the child widget does not implement :obj:`~gi.repository.Gtk.Scrollable`, the scrolled window will add the child to a :obj:`~gi.repository.Gtk.Viewport` and then set the viewport as the child. .. attribute:: props.hadjustment :type: ~gi.repository.Gtk.Adjustment .. attribute:: props.has_frame :type: bool Whether to draw a frame around the contents. .. attribute:: props.hscrollbar_policy :type: ~gi.repository.Gtk.PolicyType When the horizontal scrollbar is displayed. Use :obj:`~gi.repository.Gtk.ScrolledWindow.set_policy` to set this property. .. attribute:: props.kinetic_scrolling :type: bool Whether kinetic scrolling is enabled or not. Kinetic scrolling only applies to devices with source ``%GDK_SOURCE_TOUCHSCREEN``. .. attribute:: props.max_content_height :type: int The maximum content height of ``scrolled_window``. .. attribute:: props.max_content_width :type: int The maximum content width of ``scrolled_window``. .. attribute:: props.min_content_height :type: int The minimum content height of ``scrolled_window``. .. attribute:: props.min_content_width :type: int The minimum content width of ``scrolled_window``. .. attribute:: props.overlay_scrolling :type: bool Whether overlay scrolling is enabled or not. If it is, the scrollbars are only added as traditional widgets when a mouse is present. Otherwise, they are overlaid on top of the content, as narrow indicators. Note that overlay scrolling can also be globally disabled, with the :obj:`~gi.repository.Gtk.Settings.props.gtk_overlay_scrolling` setting. .. attribute:: props.propagate_natural_height :type: bool Whether the natural height of the child should be calculated and propagated through the scrolled window’s requested natural height. This is useful in cases where an attempt should be made to allocate exactly enough space for the natural size of the child. .. attribute:: props.propagate_natural_width :type: bool Whether the natural width of the child should be calculated and propagated through the scrolled window’s requested natural width. This is useful in cases where an attempt should be made to allocate exactly enough space for the natural size of the child. .. attribute:: props.vadjustment :type: ~gi.repository.Gtk.Adjustment .. attribute:: props.vscrollbar_policy :type: ~gi.repository.Gtk.PolicyType When the vertical scrollbar is displayed. Use :obj:`~gi.repository.Gtk.ScrolledWindow.set_policy` to set this property. .. attribute:: props.window_placement :type: ~gi.repository.Gtk.CornerType Where the contents are located with respect to the scrollbars. Signals ------- .. rst-class:: interim-class .. class:: ScrolledWindow.signals :no-index: .. method:: edge_overshot(pos: ~gi.repository.Gtk.PositionType) -> None Emitted whenever user initiated scrolling makes the scrolled window firmly surpass the limits defined by the adjustment in that orientation. A similar behavior without edge resistance is provided by the :obj:`~gi.repository.Gtk.ScrolledWindow.signals.edge_reached` signal. Note: The ``pos`` argument is LTR/RTL aware, so callers should be aware too if intending to provide behavior on horizontal edges. :param pos: edge side that was hit .. method:: edge_reached(pos: ~gi.repository.Gtk.PositionType) -> None Emitted whenever user-initiated scrolling makes the scrolled window exactly reach the lower or upper limits defined by the adjustment in that orientation. A similar behavior with edge resistance is provided by the :obj:`~gi.repository.Gtk.ScrolledWindow.signals.edge_overshot` signal. Note: The ``pos`` argument is LTR/RTL aware, so callers should be aware too if intending to provide behavior on horizontal edges. :param pos: edge side that was reached .. method:: move_focus_out(direction_type: ~gi.repository.Gtk.DirectionType) -> None Emitted when focus is moved away from the scrolled window by a keybinding. This is a `keybinding signal `_. The default bindings for this signal are `Ctrl + Tab` to move forward and `Ctrl + Shift + Tab` to move backward. :param direction_type: either :const:`~gi.repository.Gtk.DirectionType.TAB_FORWARD` or :const:`~gi.repository.Gtk.DirectionType.TAB_BACKWARD` .. method:: scroll_child(scroll: ~gi.repository.Gtk.ScrollType, horizontal: bool) -> bool Emitted when a keybinding that scrolls is pressed. This is a `keybinding signal `_. The horizontal or vertical adjustment is updated which triggers a signal that the scrolled window’s child may listen to and scroll itself. :param scroll: a ``GtkScrollType`` describing how much to scroll :param horizontal: whether the keybinding scrolls the child horizontally or not