Utilities

Utility functions for widget lookup, event position handling, and Qt compat.

qgis_macros.utils.is_object_map_canvas(obj)[source]

Return True if obj is the map canvas viewport widget.

Parameters:

obj (_QObjectStub)

Return type:

bool

qgis_macros.utils.get_widget_text(widget)[source]

Return the display text of widget, falling back to its object name.

Parameters:

widget (_QWidgetStub)

Return type:

str

qgis_macros.utils.get_sibling_index(widget, parent)[source]

Get the index of a widget among its same-class siblings in the parent.

Parameters:
  • widget (_QWidgetStub)

  • parent (_QWidgetStub)

Return type:

int

qgis_macros.utils.find_nearest_visible_children_of_type(target_point, parent_widget, widget_class)[source]

Yield visible children of widget_class sorted by distance to target_point.

Parameters:
  • target_point (_Stub)

  • parent_widget (_QWidgetStub)

  • widget_class (str)

Return type:

Iterator[_QWidgetStub]

qgis_macros.utils.find_nearest_visible_children_with_threshold(target_point, parent_widget)[source]

Yield all visible descendants of parent_widget sorted by distance.

Parameters:
  • target_point (_Stub)

  • parent_widget (_QWidgetStub)

Return type:

Iterator[_QWidgetStub]

qgis_macros.utils.enum_value(enum_or_flag)[source]

Convert a Qt enum/flag to int, compatible with both PyQt5 and PyQt6.

Parameters:

enum_or_flag (object)

Return type:

int

qgis_macros.utils.event_pos(event)[source]

Get local position from a mouse/wheel event (PyQt5/6 compatible).

Parameters:

event (_Stub)

Return type:

_Stub

qgis_macros.utils.event_global_pos(event)[source]

Get global position from a mouse/wheel event (PyQt5/6 compatible).

Parameters:

event (_Stub)

Return type:

_Stub