Gtk.ScrolledWindow¶
Example¶
- Subclasses:
Methods¶
- Inherited:
Gtk.Bin (1), Gtk.Container (35), Gtk.Widget (278), GObject.Object (37), Gtk.Buildable (10)
- Structs:
Gtk.ContainerClass (5), Gtk.WidgetClass (12), GObject.ObjectClass (5)
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
|
|
|
Properties¶
- Inherited:
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r/w/c |
The |
||
r/w/en |
When the horizontal scrollbar is displayed |
||
r/w/en |
Kinetic scrolling mode. |
||
r/w/en |
The maximum height that the scrolled window will allocate to its content |
||
r/w/en |
The maximum width that the scrolled window will allocate to its content |
||
r/w/en |
The minimum height that the scrolled window will allocate to its content |
||
r/w/en |
The minimum width that the scrolled window will allocate to its content |
||
r/w/en |
Overlay scrolling mode |
||
r/w/en |
Propagate Natural Height |
||
r/w/en |
Propagate Natural Width |
||
r/w/en |
Style of bevel around the contents |
||
r/w/c |
The |
||
r/w/en |
When the vertical scrollbar is displayed |
||
r/w/en |
Where the contents are located with respect to the scrollbars. |
||
r/w/en |
Whether “window-placement” should be used to determine the location of the contents with respect to the scrollbars. |
Style Properties¶
- Inherited:
Name |
Type |
Default |
Flags |
Short Description |
---|---|---|---|---|
|
|
r |
Number of pixels between the scrollbars and the scrolled window |
|
|
d/r |
Place scrollbars within the scrolled window’s bevel |
Signals¶
- Inherited:
Name |
Short Description |
---|---|
The |
|
The |
|
The |
|
The |
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
---|---|---|---|
container |
r |
Class Details¶
- class Gtk.ScrolledWindow(*args, **kwargs)¶
- Bases:
- Abstract:
No
- Structure:
Gtk.ScrolledWindow
is a container that accepts a single child widget and makes that child scrollable using either internally added scrollbars or externally associated adjustments.Widgets with native scrolling support, i.e. those whose classes implement the
Gtk.Scrollable
interface, are added directly. For other types of widget, the classGtk.Viewport
acts as an adaptor, giving scrollability to other widgets.Gtk.ScrolledWindow
’s implementation ofGtk.Container.add
() intelligently accounts for whether or not the added child is aGtk.Scrollable
. If it isn’t,Gtk.ScrolledWindow
wraps the child in aGtk.Viewport
and adds that for you. Therefore, you can just add any child widget and not worry about the details.If
Gtk.Container.add
() has added aGtk.Viewport
for you, you can remove both your added child widget from theGtk.Viewport
, and theGtk.Viewport
from theGtk.ScrolledWindow
, like this:GtkWidget *scrolled_window = gtk_scrolled_window_new (NULL, NULL); GtkWidget *child_widget = gtk_button_new (); // GtkButton is not a GtkScrollable, so GtkScrolledWindow will automatically // add a GtkViewport. gtk_container_add (GTK_CONTAINER (scrolled_window), child_widget); // Either of these will result in child_widget being unparented: gtk_container_remove (GTK_CONTAINER (scrolled_window), child_widget); // or gtk_container_remove (GTK_CONTAINER (scrolled_window), gtk_bin_get_child (GTK_BIN (scrolled_window)));
Unless
Gtk.ScrolledWindow
:policy
isGtk.PolicyType.NEVER
orGtk.PolicyType.EXTERNAL
,Gtk.ScrolledWindow
adds internalGtk.Scrollbar
widgets around its child. The scroll position of the child, and if applicable the scrollbars, is controlled by theGtk.ScrolledWindow
:hadjustment
andGtk.ScrolledWindow
:vadjustment
that are associated with theGtk.ScrolledWindow
. See the docs onGtk.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
Gtk.ScrolledWindow
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 withGtk.Scrollbar
and for example aGtk.Grid
.- Touch support
Gtk.ScrolledWindow
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 theGtk.ScrolledWindow
:kinetic-scrolling
property if it is undesired.Gtk.ScrolledWindow
also displays visual ‘overshoot’ indication when the content is pulled beyond the end, and this situation can be captured with theGtk.ScrolledWindow
::edge-overshot
signal.If no mouse device is present, the scrollbars will overlayed 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
Gtk.ScrolledWindow
:overlay-scrolling
property.- CSS nodes
Gtk.ScrolledWindow
has a main CSS node with name scrolledwindow.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.
Gtk.ScrolledWindow
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.
- classmethod new(hadjustment, vadjustment)[source]¶
- Parameters:
hadjustment (
Gtk.Adjustment
orNone
) – horizontal adjustmentvadjustment (
Gtk.Adjustment
orNone
) – vertical adjustment
- Returns:
a new scrolled window
- Return type:
Creates a new scrolled window.
The two arguments are the scrolled window’s adjustments; these will be shared with the scrollbars and the child widget to keep the bars in sync with the child. Usually you want to pass
None
for the adjustments, which will cause the scrolled window to create them for you.
- add_with_viewport(child)[source]¶
- Parameters:
child (
Gtk.Widget
) – the widget you want to scroll
Used to add children without native scrolling capabilities. This is simply a convenience function; it is equivalent to adding the unscrollable child to a viewport, then adding the viewport to the scrolled window. If a child has native scrolling, use
Gtk.Container.add
() instead of this function.The viewport scrolls the child by moving its
Gdk.Window
, and takes the size of the child to be the size of its toplevelGdk.Window
. This will be very wrong for most widgets that support native scrolling; for example, if you add a widget such asGtk.TreeView
with a viewport, the whole widget will scroll, including the column headings. Thus, widgets with native scrolling support should not be used with theGtk.Viewport
proxy.A widget supports scrolling natively if it implements the
Gtk.Scrollable
interface.Deprecated since version 3.8:
Gtk.Container.add
() will automatically add aGtk.Viewport
if the child doesn’t implementGtk.Scrollable
.
- get_capture_button_press()[source]¶
-
Return whether button presses are captured during kinetic scrolling. See
Gtk.ScrolledWindow.set_capture_button_press
().New in version 3.4.
- get_hadjustment()[source]¶
- Returns:
the horizontal
Gtk.Adjustment
- Return type:
Returns the horizontal scrollbar’s adjustment, used to connect the horizontal scrollbar to the child widget’s horizontal scroll functionality.
- get_hscrollbar()[source]¶
- Returns:
the horizontal scrollbar of the scrolled window.
- Return type:
Returns the horizontal scrollbar of self.
New in version 2.8.
- get_kinetic_scrolling()[source]¶
- Returns:
the scrolling behavior flags.
- Return type:
Returns the specified kinetic scrolling behavior.
New in version 3.4.
- get_max_content_height()[source]¶
- Returns:
the maximum content height, or -1
- Return type:
Returns the maximum content height set.
New in version 3.22.
- get_max_content_width()[source]¶
- Returns:
the maximum content width, or -1
- Return type:
Returns the maximum content width set.
New in version 3.22.
- get_min_content_height()[source]¶
- Returns:
the minimal content height
- Return type:
Gets the minimal content height of self, or -1 if not set.
New in version 3.0.
- get_min_content_width()[source]¶
- Returns:
the minimum content width
- Return type:
Gets the minimum content width of self, or -1 if not set.
New in version 3.0.
- get_overlay_scrolling()[source]¶
-
Returns whether overlay scrolling is enabled for this scrolled window.
New in version 3.16.
- get_placement()[source]¶
- Returns:
the current placement value.
See also
Gtk.ScrolledWindow.set_placement
() andGtk.ScrolledWindow.unset_placement
().- Return type:
Gets the placement of the contents with respect to the scrollbars for the scrolled window. See
Gtk.ScrolledWindow.set_placement
().
- get_policy()[source]¶
- Returns:
- Return type:
(hscrollbar_policy:
Gtk.PolicyType
, vscrollbar_policy:Gtk.PolicyType
)
Retrieves the current policy values for the horizontal and vertical scrollbars. See
Gtk.ScrolledWindow.set_policy
().
- get_propagate_natural_height()[source]¶
- Returns:
whether natural height propagation is enabled.
- Return type:
Reports whether the natural height of the child will be calculated and propagated through the scrolled window’s requested natural height.
New in version 3.22.
- get_propagate_natural_width()[source]¶
- Returns:
whether natural width propagation is enabled.
- Return type:
Reports whether the natural width of the child will be calculated and propagated through the scrolled window’s requested natural width.
New in version 3.22.
- get_shadow_type()[source]¶
- Returns:
the current shadow type
- Return type:
Gets the shadow type of the scrolled window. See
Gtk.ScrolledWindow.set_shadow_type
().
- get_vadjustment()[source]¶
- Returns:
the vertical
Gtk.Adjustment
- Return type:
Returns the vertical scrollbar’s adjustment, used to connect the vertical scrollbar to the child widget’s vertical scroll functionality.
- get_vscrollbar()[source]¶
- Returns:
the vertical scrollbar of the scrolled window.
- Return type:
Returns the vertical scrollbar of self.
New in version 2.8.
- set_capture_button_press(capture_button_press)[source]¶
-
Changes the behaviour of self with regard to the initial event that possibly starts kinetic scrolling. When capture_button_press is set to
True
, the event is captured by the scrolled window, and then later replayed if it is meant to go to the child widget.This should be enabled if any child widgets perform non-reversible actions on
Gtk.Widget
::button-press-event
. If they don’t, and handle additionally handleGtk.Widget
::grab-broken-event
, it might be better to set capture_button_press toFalse
.This setting only has an effect if kinetic scrolling is enabled.
New in version 3.4.
- set_hadjustment(hadjustment)[source]¶
- Parameters:
hadjustment (
Gtk.Adjustment
orNone
) – theGtk.Adjustment
to use, orNone
to create a new one
Sets the
Gtk.Adjustment
for the horizontal scrollbar.
- set_kinetic_scrolling(kinetic_scrolling)[source]¶
-
Turns kinetic scrolling on or off. Kinetic scrolling only applies to devices with source
Gdk.InputSource.TOUCHSCREEN
.New in version 3.4.
- set_max_content_height(height)[source]¶
- Parameters:
height (
int
) – the maximum content height
Sets the maximum height that self should keep visible. The self 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
Gtk.ScrolledWindow
:min-content-height
.New in version 3.22.
- set_max_content_width(width)[source]¶
- Parameters:
width (
int
) – the maximum content width
Sets the maximum width that self should keep visible. The self 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
Gtk.ScrolledWindow
:min-content-width
.New in version 3.22.
- set_min_content_height(height)[source]¶
- Parameters:
height (
int
) – the minimal content height
Sets the minimum height that self 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
Gtk.ScrolledWindow
:max-content-height
.New in version 3.0.
- set_min_content_width(width)[source]¶
- Parameters:
width (
int
) – the minimal content width
Sets the minimum width that self 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
Gtk.ScrolledWindow
:max-content-width
.New in version 3.0.
- set_overlay_scrolling(overlay_scrolling)[source]¶
- Parameters:
overlay_scrolling (
bool
) – whether to enable overlay scrolling
Enables or disables overlay scrolling for this scrolled window.
New in version 3.16.
- set_placement(window_placement)[source]¶
- Parameters:
window_placement (
Gtk.CornerType
) – position of the child window
Sets the placement of the contents with respect to the scrollbars for the scrolled window.
The default is
Gtk.CornerType.TOP_LEFT
, meaning the child is in the top left, with the scrollbars underneath and to the right. Other values inGtk.CornerType
areGtk.CornerType.TOP_RIGHT
,Gtk.CornerType.BOTTOM_LEFT
, andGtk.CornerType.BOTTOM_RIGHT
.See also
Gtk.ScrolledWindow.get_placement
() andGtk.ScrolledWindow.unset_placement
().
- set_policy(hscrollbar_policy, vscrollbar_policy)[source]¶
- Parameters:
hscrollbar_policy (
Gtk.PolicyType
) – policy for horizontal barvscrollbar_policy (
Gtk.PolicyType
) – policy for vertical bar
Sets the scrollbar policy for the horizontal and vertical scrollbars.
The policy determines when the scrollbar should appear; it is a value from the
Gtk.PolicyType
enumeration. IfGtk.PolicyType.ALWAYS
, the scrollbar is always present; ifGtk.PolicyType.NEVER
, the scrollbar is never present; ifGtk.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).
- set_propagate_natural_height(propagate)[source]¶
- Parameters:
propagate (
bool
) – whether to propagate natural height
Sets whether the natural height of the child should be calculated and propagated through the scrolled window’s requested natural height.
New in version 3.22.
- set_propagate_natural_width(propagate)[source]¶
- Parameters:
propagate (
bool
) – whether to propagate natural width
Sets whether the natural width of the child should be calculated and propagated through the scrolled window’s requested natural width.
New in version 3.22.
- set_shadow_type(type)[source]¶
- Parameters:
type (
Gtk.ShadowType
) – kind of shadow to draw around scrolled window contents
Changes the type of shadow drawn around the contents of self.
- set_vadjustment(vadjustment)[source]¶
- Parameters:
vadjustment (
Gtk.Adjustment
orNone
) – theGtk.Adjustment
to use, orNone
to create a new one
Sets the
Gtk.Adjustment
for the vertical scrollbar.
- unset_placement()[source]¶
Unsets the placement of the contents with respect to the scrollbars for the scrolled window. If no window placement is set for a scrolled window, it defaults to
Gtk.CornerType.TOP_LEFT
.See also
Gtk.ScrolledWindow.set_placement
() andGtk.ScrolledWindow.get_placement
().New in version 2.10.
- do_move_focus_out(direction) virtual¶
- Parameters:
direction (
Gtk.DirectionType
) –
Keybinding signal which gets emitted when focus is moved away from the scrolled window by a keybinding.
- do_scroll_child(scroll, horizontal) virtual¶
- Parameters:
scroll (
Gtk.ScrollType
) –horizontal (
bool
) –
- Return type:
Keybinding signal which gets emitted when a keybinding that scrolls is pressed.
Signal Details¶
- Gtk.ScrolledWindow.signals.edge_overshot(scrolled_window, pos)¶
- Signal Name:
edge-overshot
- Flags:
- Parameters:
scrolled_window (
Gtk.ScrolledWindow
) – The object which received the signalpos (
Gtk.PositionType
) – edge side that was hit
The
::edge-overshot
signal is emitted whenever user initiated scrolling makes the scrolled window firmly surpass (i.e. with some edge resistance) the lower or upper limits defined by the adjustment in that orientation.A similar behavior without edge resistance is provided by the
Gtk.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.
New in version 3.16.
- Gtk.ScrolledWindow.signals.edge_reached(scrolled_window, pos)¶
- Signal Name:
edge-reached
- Flags:
- Parameters:
scrolled_window (
Gtk.ScrolledWindow
) – The object which received the signalpos (
Gtk.PositionType
) – edge side that was reached
The
::edge-reached
signal is 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
Gtk.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.
New in version 3.16.
- Gtk.ScrolledWindow.signals.move_focus_out(scrolled_window, direction_type)¶
- Signal Name:
move-focus-out
- Flags:
- Parameters:
scrolled_window (
Gtk.ScrolledWindow
) – The object which received the signaldirection_type (
Gtk.DirectionType
) – eitherGtk.DirectionType.TAB_FORWARD
orGtk.DirectionType.TAB_BACKWARD
The
::move-focus-out
signal is akeybinding signal
which gets emitted when focus is moved away from the scrolled window by a keybinding. TheGtk.Widget
::move-focus
signal is emitted with direction_type on this scrolled window’s toplevel parent in the container hierarchy. The default bindings for this signal areCtrl + Tab
to move forward andCtrl + Shift + Tab
to move backward.
- Gtk.ScrolledWindow.signals.scroll_child(scrolled_window, scroll, horizontal)¶
- Signal Name:
scroll-child
- Flags:
- Parameters:
scrolled_window (
Gtk.ScrolledWindow
) – The object which received the signalscroll (
Gtk.ScrollType
) – aGtk.ScrollType
describing how much to scrollhorizontal (
bool
) – whether the keybinding scrolls the child horizontally or not
- Return type:
The
::scroll-child
signal is akeybinding signal
which gets emitted when a keybinding that scrolls is pressed. The horizontal or vertical adjustment is updated which triggers a signal that the scrolled window’s child may listen to and scroll itself.
Property Details¶
- Gtk.ScrolledWindow.props.hadjustment¶
- Name:
hadjustment
- Type:
- Default Value:
- Flags:
The
Gtk.Adjustment
for the horizontal position
- Gtk.ScrolledWindow.props.hscrollbar_policy¶
- Name:
hscrollbar-policy
- Type:
- Default Value:
- Flags:
When the horizontal scrollbar is displayed
- Gtk.ScrolledWindow.props.kinetic_scrolling¶
- Name:
kinetic-scrolling
- Type:
- Default Value:
- Flags:
Whether kinetic scrolling is enabled or not. Kinetic scrolling only applies to devices with source
Gdk.InputSource.TOUCHSCREEN
.New in version 3.4.
- Gtk.ScrolledWindow.props.max_content_height¶
- Name:
max-content-height
- Type:
- Default Value:
-1
- Flags:
The maximum content height of scrolled_window, or -1 if not set.
New in version 3.22.
- Gtk.ScrolledWindow.props.max_content_width¶
- Name:
max-content-width
- Type:
- Default Value:
-1
- Flags:
The maximum content width of scrolled_window, or -1 if not set.
New in version 3.22.
- Gtk.ScrolledWindow.props.min_content_height¶
- Name:
min-content-height
- Type:
- Default Value:
-1
- Flags:
The minimum content height of scrolled_window, or -1 if not set.
New in version 3.0.
- Gtk.ScrolledWindow.props.min_content_width¶
- Name:
min-content-width
- Type:
- Default Value:
-1
- Flags:
The minimum content width of scrolled_window, or -1 if not set.
New in version 3.0.
- Gtk.ScrolledWindow.props.overlay_scrolling¶
- Name:
overlay-scrolling
- Type:
- Default Value:
- Flags:
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 overlayed on top of the content, as narrow indicators.
Note that overlay scrolling can also be globally disabled, with the
Gtk.Settings
::gtk-overlay-scrolling
setting.New in version 3.16.
- Gtk.ScrolledWindow.props.propagate_natural_height¶
- Name:
propagate-natural-height
- Type:
- Default Value:
- Flags:
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.
New in version 3.22.
- Gtk.ScrolledWindow.props.propagate_natural_width¶
- Name:
propagate-natural-width
- Type:
- Default Value:
- Flags:
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.
New in version 3.22.
- Gtk.ScrolledWindow.props.shadow_type¶
- Name:
shadow-type
- Type:
- Default Value:
- Flags:
Style of bevel around the contents
- Gtk.ScrolledWindow.props.vadjustment¶
- Name:
vadjustment
- Type:
- Default Value:
- Flags:
The
Gtk.Adjustment
for the vertical position
- Gtk.ScrolledWindow.props.vscrollbar_policy¶
- Name:
vscrollbar-policy
- Type:
- Default Value:
- Flags:
When the vertical scrollbar is displayed
- Gtk.ScrolledWindow.props.window_placement¶
- Name:
window-placement
- Type:
- Default Value:
- Flags:
Where the contents are located with respect to the scrollbars.
- Gtk.ScrolledWindow.props.window_placement_set¶
- Name:
window-placement-set
- Type:
- Default Value:
- Flags:
Whether “window-placement” should be used to determine the location of the contents with respect to the scrollbars.
New in version 2.10.
Deprecated since version 3.10: This value is ignored and
Gtk.ScrolledWindow
:window-placement
value is always honored.