Skip to content

Gtk.DragIcon

class — extends Widget, Accessible, Buildable, ConstraintTarget, Native, Root

A GtkRoot implementation for drag icons.

A drag icon moves with the pointer during a Drag-and-Drop operation and is destroyed when the drag ends.

To set up a drag icon and associate it with an ongoing drag operation, use DragIcon.get_for_drag to get the icon for a drag. You can then use it like any other widget and use DragIcon.set_child to set whatever widget should be used for the drag icon.

Keep in mind that drag icons do not allow user input.

Constructors

get_for_drag

@classmethod
def get_for_drag(cls, drag: Gdk.Drag) -> Widget

Gets the GtkDragIcon in use with drag.

If no drag icon exists yet, a new one will be created and shown.

Parameters:

  • drag — a GdkDrag

Methods

get_child

def get_child(self) -> Widget | None

Gets the widget currently used as drag icon.

set_child

def set_child(self, child: Widget | None = ...) -> None

Sets the widget to display as the drag icon.

Parameters:

  • child — a GtkWidget

Static functions

create_widget_for_value

@staticmethod
def create_widget_for_value(value: GObject.Value) -> Widget | None

Creates a widget that can be used as a drag icon for the given value.

Supported types include strings, GdkRGBA and GtkTextBuffer. If GTK does not know how to create a widget for a given value, it will return None.

This method is used to set the default drag icon on drag-and-drop operations started by GtkDragSource, so you don't need to set a drag icon using this function there.

Parameters:

  • value — a GValue

set_from_paintable

@staticmethod
def set_from_paintable(drag: Gdk.Drag, paintable: Gdk.Paintable, hot_x: int, hot_y: int) -> None

Creates a GtkDragIcon that shows paintable, and associates it with the drag operation.

The hotspot position on the paintable is aligned with the hotspot of the cursor.

Parameters:

  • drag — a GdkDrag
  • paintable — a GdkPaintable to display
  • hot_x — X coordinate of the hotspot
  • hot_y — Y coordinate of the hotspot

Properties

child

child: Widget  # read/write

The widget to display as drag icon.