Gdk.Cursor

g GObject.Object GObject.Object Gdk.Cursor Gdk.Cursor GObject.Object->Gdk.Cursor

Subclasses:

None

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

class

new_from_name (name, fallback)

class

new_from_texture (texture, hotspot_x, hotspot_y, fallback)

get_fallback ()

get_hotspot_x ()

get_hotspot_y ()

get_name ()

get_texture ()

Virtual Methods

Inherited:

GObject.Object (7)

Properties

Name

Type

Flags

Short Description

fallback

Gdk.Cursor

r/w/co

hotspot-x

int

r/w/co

hotspot-y

int

r/w/co

name

str

r/w/co

texture

Gdk.Texture

r/w/co

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Class Details

class Gdk.Cursor(**kwargs)
Bases:

GObject.Object

Abstract:

No

GdkCursor is used to create and destroy cursors.

Cursors are immutable objects, so once you created them, there is no way to modify them later. You should create a new cursor when you want to change something about it.

Cursors by themselves are not very interesting: they must be bound to a window for users to see them. This is done with [method`Gdk`.Surface.set_cursor] or [method`Gdk`.Surface.set_device_cursor]. Applications will typically use higher-level GTK functions such as gtk_widget_set_cursor() instead.

Cursors are not bound to a given [class`Gdk`.Display], so they can be shared. However, the appearance of cursors may vary when used on different platforms.

Named and texture cursors

There are multiple ways to create cursors. The platform’s own cursors can be created with [ctor`Gdk`.Cursor.new_from_name]. That function lists the commonly available names that are shared with the CSS specification. Other names may be available, depending on the platform in use. On some platforms, what images are used for named cursors may be influenced by the cursor theme.

Another option to create a cursor is to use [ctor`Gdk`.Cursor.new_from_texture] and provide an image to use for the cursor.

To ease work with unsupported cursors, a fallback cursor can be provided. If a [class`Gdk`.Surface] cannot use a cursor because of the reasons mentioned above, it will try the fallback cursor. Fallback cursors can themselves have fallback cursors again, so it is possible to provide a chain of progressively easier to support cursors. If none of the provided cursors can be supported, the default cursor will be the ultimate fallback.

classmethod new_from_name(name, fallback)[source]
Parameters:
  • name (str) – the name of the cursor

  • fallback (Gdk.Cursor or None) – None or the GdkCursor to fall back to when this one cannot be supported

Returns:

a new GdkCursor, or None if there is no cursor with the given name

Return type:

Gdk.Cursor or None

Creates a new cursor by looking up name in the current cursor theme.

A recommended set of cursor names that will work across different platforms can be found in the CSS specification:

| | | |
— | — | —- | — |
“none” | “default” | “help” | “pointer” |
“context-menu” | “progress” | “wait” | “cell” |
“crosshair” | “text” | “vertical-text” | “alias” |
“copy” | “no-drop” | “move” | “not-allowed” |
“grab” | “grabbing” | “all-scroll” | “col-resize” |
“row-resize” | “n-resize” | “e-resize” | “s-resize” |
“w-resize” | “ne-resize” | “nw-resize” | “sw-resize” |
“se-resize” | “ew-resize” | “ns-resize” | “nesw-resize” |
“nwse-resize” | “zoom-in” | “zoom-out” | |
classmethod new_from_texture(texture, hotspot_x, hotspot_y, fallback)[source]
Parameters:
  • texture (Gdk.Texture) – the texture providing the pixel data

  • hotspot_x (int) – the horizontal offset of the “hotspot” of the cursor

  • hotspot_y (int) – the vertical offset of the “hotspot” of the cursor

  • fallback (Gdk.Cursor or None) – the GdkCursor to fall back to when this one cannot be supported

Returns:

a new GdkCursor

Return type:

Gdk.Cursor

Creates a new cursor from a GdkTexture.

get_fallback()[source]
Returns:

the fallback of the cursor or None to use the default cursor as fallback

Return type:

Gdk.Cursor or None

Returns the fallback for this self.

The fallback will be used if this cursor is not available on a given GdkDisplay. For named cursors, this can happen when using nonstandard names or when using an incomplete cursor theme. For textured cursors, this can happen when the texture is too large or when the GdkDisplay it is used on does not support textured cursors.

get_hotspot_x()[source]
Returns:

the horizontal offset of the hotspot or 0 for named cursors

Return type:

int

Returns the horizontal offset of the hotspot.

The hotspot indicates the pixel that will be directly above the cursor.

Note that named cursors may have a nonzero hotspot, but this function will only return the hotspot position for cursors created with [ctor`Gdk`.Cursor.new_from_texture].

get_hotspot_y()[source]
Returns:

the vertical offset of the hotspot or 0 for named cursors

Return type:

int

Returns the vertical offset of the hotspot.

The hotspot indicates the pixel that will be directly above the cursor.

Note that named cursors may have a nonzero hotspot, but this function will only return the hotspot position for cursors created with [ctor`Gdk`.Cursor.new_from_texture].

get_name()[source]
Returns:

the name of the cursor or None if it is not a named cursor

Return type:

str or None

Returns the name of the cursor.

If the cursor is not a named cursor, None will be returned.

get_texture()[source]
Returns:

the texture for cursor or None if it is a named cursor

Return type:

Gdk.Texture or None

Returns the texture for the cursor.

If the cursor is a named cursor, None will be returned.

Property Details

Gdk.Cursor.props.fallback
Name:

fallback

Type:

Gdk.Cursor

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

Cursor to fall back to if this cursor cannot be displayed.

Gdk.Cursor.props.hotspot_x
Name:

hotspot-x

Type:

int

Default Value:

0

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

X position of the cursor hotspot in the cursor image.

Gdk.Cursor.props.hotspot_y
Name:

hotspot-y

Type:

int

Default Value:

0

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

Y position of the cursor hotspot in the cursor image.

Gdk.Cursor.props.name
Name:

name

Type:

str

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

Name of this this cursor.

The name will be None if the cursor was created from a texture.

Gdk.Cursor.props.texture
Name:

texture

Type:

Gdk.Texture

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

The texture displayed by this cursor.

The texture will be None if the cursor was created from a name.