Gtk.ScrolledWindow¶
class — extends Widget, Accessible, Buildable, ConstraintTarget
Makes its child scrollable.
<picture> <source srcset="scrolledwindow-dark.png" media="(prefers-color-scheme: dark)"> <img alt="An example GtkScrolledWindow" src="scrolledwindow.png"> </picture>
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 Scrollable interface, are added directly. For other types
of widget, the class Viewport acts as an adaptor, giving
scrollability to other widgets. 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 ScrolledWindow.set_child has added a GtkViewport for you,
it will be automatically removed when you unset the child.
Unless ScrolledWindow.hscrollbar-policy and
ScrolledWindow.vscrollbar-policy are PolicyType.NEVER or
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 ScrolledWindow.hadjustment
and ScrolledWindow.vadjustment that are associated with the
GtkScrolledWindow. See the docs on 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
ScrolledWindow.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 ScrolledWindow.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 ScrolledWindow.overlay-scrolling
property.
Shortcuts and Gestures¶
The following signals have default keybindings:
CSS nodes¶
GtkScrolledWindow has a main CSS node with name scrolledwindow.
It gets a .frame style class added when ScrolledWindow.has-frame
is 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 AccessibleRole.group role.
Starting from GTK 4.12, GtkScrolledWindow uses the AccessibleRole.generic
role.
Constructors¶
new¶
Creates a new scrolled window.
Methods¶
get_child¶
Gets the child widget of scrolled_window.
If the scrolled window automatically added a Viewport, this
function will return the viewport widget, and you can retrieve its child
using Viewport.get_child.
get_hadjustment¶
Returns the horizontal scrollbar’s adjustment.
This is the adjustment used to connect the horizontal scrollbar to the child widget’s horizontal scroll functionality.
get_has_frame¶
Gets whether the scrolled window draws a frame.
get_hscrollbar¶
Returns the horizontal scrollbar of scrolled_window.
get_kinetic_scrolling¶
Returns the specified kinetic scrolling behavior.
get_max_content_height¶
Returns the maximum content height set.
get_max_content_width¶
Returns the maximum content width set.
get_min_content_height¶
Gets the minimal content height of scrolled_window.
get_min_content_width¶
Gets the minimum content width of scrolled_window.
get_overlay_scrolling¶
Returns whether overlay scrolling is enabled for this scrolled window.
get_placement¶
Gets the placement of the contents with respect to the scrollbars.
get_policy¶
Retrieves the current policy values for the horizontal and vertical scrollbars.
See ScrolledWindow.set_policy.
get_propagate_natural_height¶
Reports whether the natural height of the child will be calculated and propagated through the scrolled window’s requested natural height.
get_propagate_natural_width¶
Reports whether the natural width of the child will be calculated and propagated through the scrolled window’s requested natural width.
get_vadjustment¶
Returns the vertical scrollbar’s adjustment.
This is the adjustment used to connect the vertical scrollbar to the child widget’s vertical scroll functionality.
get_vscrollbar¶
Returns the vertical scrollbar of scrolled_window.
set_child¶
Sets the child widget of scrolled_window.
If child does not implement the Scrollable interface,
the scrolled window will add child to a Viewport instance
and then add the viewport as its child widget.
Parameters:
child— the child widget
set_hadjustment¶
Sets the GtkAdjustment for the horizontal scrollbar.
Parameters:
hadjustment— theGtkAdjustmentto use, orNoneto create a new one
set_has_frame¶
Changes the frame drawn around the contents of scrolled_window.
Parameters:
has_frame— whether to draw a frame around scrolled window contents
set_kinetic_scrolling¶
Turns kinetic scrolling on or off.
Kinetic scrolling only applies to devices with source
Gdk.InputSource.TOUCHSCREEN.
Parameters:
kinetic_scrolling—Trueto enable kinetic scrolling
set_max_content_height¶
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 ScrolledWindow.min-content-height.
Parameters:
height— the maximum content height
set_max_content_width¶
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 ScrolledWindow.min-content-width.
Parameters:
width— the maximum content width
set_min_content_height¶
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 ScrolledWindow.max-content-height.
Parameters:
height— the minimal content height
set_min_content_width¶
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 ScrolledWindow.max-content-width.
Parameters:
width— the minimal content width
set_overlay_scrolling¶
Enables or disables overlay scrolling for this scrolled window.
Parameters:
overlay_scrolling— whether to enable overlay scrolling
set_placement¶
Sets the placement of the contents with respect to the scrollbars for the scrolled window.
The default is CornerType.TOP_LEFT, meaning the child is
in the top left, with the scrollbars underneath and to the right.
Other values in CornerType are CornerType.TOP_RIGHT,
CornerType.BOTTOM_LEFT, and CornerType.BOTTOM_RIGHT.
See also ScrolledWindow.get_placement and
ScrolledWindow.unset_placement.
Parameters:
window_placement— position of the child window
set_policy¶
def set_policy(self, hscrollbar_policy: PolicyType | int, vscrollbar_policy: PolicyType | int) -> 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 PolicyType enumeration. If PolicyType.ALWAYS, the
scrollbar is always present; if PolicyType.NEVER, the scrollbar is
never present; if 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).
Parameters:
hscrollbar_policy— policy for horizontal barvscrollbar_policy— policy for vertical bar
set_propagate_natural_height¶
Sets whether the natural height of the child should be calculated and propagated through the scrolled window’s requested natural height.
Parameters:
propagate— whether to propagate natural height
set_propagate_natural_width¶
Sets whether the natural width of the child should be calculated and propagated through the scrolled window’s requested natural width.
Parameters:
propagate— whether to propagate natural width
set_vadjustment¶
Sets the GtkAdjustment for the vertical scrollbar.
Parameters:
vadjustment— theGtkAdjustmentto use, orNoneto create a new one
unset_placement¶
Unsets the placement of the contents with respect to the scrollbars.
If no window placement is set for a scrolled window,
it defaults to CornerType.TOP_LEFT.
Properties¶
child¶
The child widget.
When setting this property, if the child widget does not implement
Scrollable, the scrolled window will add the child to
a Viewport and then set the viewport as the child.
hadjustment¶
The GtkAdjustment for the horizontal position.
has_frame¶
Whether to draw a frame around the contents.
hscrollbar_policy¶
When the horizontal scrollbar is displayed.
Use ScrolledWindow.set_policy to set
this property.
kinetic_scrolling¶
Whether kinetic scrolling is enabled or not.
Kinetic scrolling only applies to devices with source Gdk.InputSource.TOUCHSCREEN.
max_content_height¶
The maximum content height of scrolled_window.
max_content_width¶
The maximum content width of scrolled_window.
min_content_height¶
The minimum content height of scrolled_window.
min_content_width¶
The minimum content width of scrolled_window.
overlay_scrolling¶
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 Settings.gtk-overlay-scrolling setting.
propagate_natural_height¶
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.
propagate_natural_width¶
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.
vadjustment¶
The GtkAdjustment for the vertical position.
vscrollbar_policy¶
When the vertical scrollbar is displayed.
Use ScrolledWindow.set_policy to set
this property.
window_placement¶
Where the contents are located with respect to the scrollbars.
Signals¶
edge-overshot¶
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
ScrolledWindow.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.
edge-reached¶
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
ScrolledWindow.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.
move-focus-out¶
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 <kbd>Ctrl</kbd>+<kbd>Tab</kbd> to move forward and <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Tab</kbd>` to move backward.
scroll-child¶
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.