Skip to content

Gtk.EventControllerScroll

class — extends EventController

Handles scroll events.

It is capable of handling both discrete and continuous scroll events from mice or touchpads, abstracting them both with the EventControllerScroll.scroll signal. Deltas in the discrete case are multiples of 1.

In the case of continuous scroll events, GtkEventControllerScroll encloses all EventControllerScroll.scroll emissions between two EventControllerScroll.scroll-begin and EventControllerScroll.scroll-end signals.

The behavior of the event controller can be modified by the flags given at creation time, or modified at a later point through EventControllerScroll.set_flags (e.g. because the scrolling conditions of the widget changed).

The controller can be set up to emit motion for either/both vertical and horizontal scroll events through EventControllerScrollFlags.VERTICAL, EventControllerScrollFlags.HORIZONTAL and EventControllerScrollFlags.BOTH_AXES. If any axis is disabled, the respective EventControllerScroll.scroll delta will be 0. Vertical scroll events will be translated to horizontal motion for the devices incapable of horizontal scrolling.

The event controller can also be forced to emit discrete events on all devices through EventControllerScrollFlags.DISCRETE. This can be used to implement discrete actions triggered through scroll events (e.g. switching across combobox options).

The EventControllerScrollFlags.KINETIC flag toggles the emission of the EventControllerScroll.decelerate signal, emitted at the end of scrolling with two X/Y velocity arguments that are consistent with the motion that was received.

Constructors

new

@classmethod
def new(cls, flags: EventControllerScrollFlags | int) -> EventController

Creates a new event controller that will handle scroll events.

Parameters:

  • flags — flags affecting the controller behavior

Methods

get_flags

def get_flags(self) -> EventControllerScrollFlags

Gets the flags conditioning the scroll controller behavior.

get_unit

def get_unit(self) -> Gdk.ScrollUnit

Gets the scroll unit of the last EventControllerScroll.scroll signal received.

Always returns Gdk.ScrollUnit.WHEEL if the EventControllerScrollFlags.DISCRETE flag is set.

set_flags

def set_flags(self, flags: EventControllerScrollFlags | int) -> None

Sets the flags conditioning scroll controller behavior.

Parameters:

  • flags — flags affecting the controller behavior

Properties

flags

flags: EventControllerScrollFlags | int  # read/write

The flags affecting event controller behavior.

Signals

decelerate

def on_decelerate(self, vel_x: float, vel_y: float) -> None: ...

Emitted after scroll is finished if the EventControllerScrollFlags.KINETIC flag is set.

vel_x and vel_y express the initial velocity that was imprinted by the scroll events. vel_x and vel_y are expressed in pixels/ms.

scroll

def on_scroll(self, dx: float, dy: float) -> bool: ...

Signals that the widget should scroll by the amount specified by dx and dy.

For the representation unit of the deltas, see EventControllerScroll.get_unit.

scroll-begin

def on_scroll_begin(self) -> None: ...

Signals that a new scrolling operation has begun.

It will only be emitted on devices capable of it.

scroll-end

def on_scroll_end(self) -> None: ...

Signals that a scrolling operation has finished.

It will only be emitted on devices capable of it.