Class: QgsEditorWidgetRegistry

A registry that manages all known edit widget factories.

QgsEditorWidgetRegistry is not usually directly created, but rather accessed through QgsGui.editorWidgetRegistry().

Class Hierarchy

Inheritance diagram of qgis.gui.QgsEditorWidgetRegistry

Base classes

QObject

class qgis.gui.QgsEditorWidgetRegistry[source]

Bases: QObject

__init__()

Constructor for QgsEditorWidgetRegistry. QgsEditorWidgetRegistry is not usually directly created, but rather accessed through QgsGui.editorWidgetRegistry().

create(self, widgetId: str | None, vl: QgsVectorLayer | None, fieldIdx: int, config: Dict[str, Any], editor: QWidget | None, parent: QWidget | None) QgsEditorWidgetWrapper | None[source]

Create an attribute editor widget wrapper of a given type for a given field. The editor may be None if you want the widget wrapper to create a default widget.

Parameters:
  • widgetId (Optional[str]) – The id of the widget type to create an attribute editor for

  • vl (Optional[QgsVectorLayer]) – The vector layer for which this widget will be created

  • fieldIdx (int) – The field index on the specified layer for which this widget will be created

  • config (Dict[str, Any]) – A configuration which should be used for the widget creation

  • editor (Optional[QWidget]) – An editor widget which will be used instead of an autocreated widget

  • parent (Optional[QWidget]) – The parent which will be used for the created wrapper and the created widget

Returns:

A new widget wrapper

create(self, vl: Optional[QgsVectorLayer], fieldIdx: int, editor: Optional[QWidget], parent: Optional[QWidget]) -> Optional[QgsEditorWidgetWrapper] Create an attribute editor widget wrapper of the best type for a given field. The editor may be None if you want the widget wrapper to create a default widget.

Parameters:
  • vl – The vector layer for which this widget will be created

  • fieldIdx – The field index on the specified layer for which this widget will be created

  • editor – An editor widget which will be used instead of an autocreated widget

  • parent – The parent which will be used for the created wrapper and the created widget

Return type:

Optional[QgsEditorWidgetWrapper]

Returns:

A new widget wrapper

createConfigWidget(self, widgetId: str | None, vl: QgsVectorLayer | None, fieldIdx: int, parent: QWidget | None) QgsEditorConfigWidget | None[source]

Creates a configuration widget

Parameters:
  • widgetId (Optional[str]) – The id of the widget type to create a configuration widget for

  • vl (Optional[QgsVectorLayer]) – The vector layer for which this widget will be created

  • fieldIdx (int) – The field index on the specified layer for which this widget will be created

  • parent (Optional[QWidget]) – The parent widget for the created widget

Return type:

Optional[QgsEditorConfigWidget]

Returns:

A new configuration widget

createSearchWidget(self, widgetId: str | None, vl: QgsVectorLayer | None, fieldIdx: int, config: Dict[str, Any], parent: QWidget | None) QgsSearchWidgetWrapper | None[source]
Parameters:
  • widgetId (Optional[str])

  • vl (Optional[QgsVectorLayer])

  • fieldIdx (int)

  • config (Dict[str, Any])

  • parent (Optional[QWidget])

Return type:

Optional[QgsSearchWidgetWrapper]

factories(self) Any

Gets access to all registered factories

Return type:

Any

Returns:

All ids and factories

factory(self, widgetId: str | None) QgsEditorWidgetFactory | None[source]

Gets a factory for the given widget type id.

Return type:

Optional[QgsEditorWidgetFactory]

Returns:

A factory or None if not existent

Parameters:

widgetId (Optional[str])

findBest(self, vl: QgsVectorLayer | None, fieldName: str | None) QgsEditorWidgetSetup[source]

Find the best editor widget and its configuration for a given field.

Parameters:
  • vl (Optional[QgsVectorLayer]) – The vector layer for which this widget will be created

  • fieldName (Optional[str]) – The field name on the specified layer for which this widget will be created

Return type:

QgsEditorWidgetSetup

Returns:

The id of the widget type to use and its config

icon(self, widgetId: str | None) QIcon[source]

Returns the icon for a widget type

Parameters:

widgetId (Optional[str]) – The widget type to get the icon for

Return type:

QIcon

Returns:

An icon

Added in version 4.0.

initEditors(self, mapCanvas: QgsMapCanvas | None = None, messageBar: QgsMessageBar | None = None)[source]

Registers all the default widgets. Only call this once on startup of an application.

Parameters:
  • mapCanvas (Optional[QgsMapCanvas] = None) – Specify a map canvas with which the widgets (relation reference) work

  • messageBar (Optional[QgsMessageBar] = None) – Specify a message bar on which messages by widgets will be shown while working with the map canvas

Note

Not required for plugins, the QGIS application does that already

isReadOnly(self, widgetId: str | None) bool[source]

Gets the widget’s read-only flag

Parameters:

widgetId (Optional[str]) – The widget type to get the read-only flag for

Added in version 3.44.

Return type:

bool

name(self, widgetId: str | None) str[source]

Returns the human readable name for a widget type

Parameters:

widgetId (Optional[str]) – The widget type to get the name for

Return type:

str

Returns:

A human readable name

registerAutoConfPlugin(self, plugin: QgsEditorWidgetAutoConfPlugin | None)[source]

Register a new auto-conf plugin.

Parameters:

plugin (Optional[QgsEditorWidgetAutoConfPlugin]) – The plugin (ownership is transferred)

registerWidget(self, widgetId: str | None, widgetFactory: QgsEditorWidgetFactory | None) bool[source]

Register a new widget factory with the given id

Parameters:
  • widgetId (Optional[str]) – The id which will be used later to refer to this widget type

  • widgetFactory (Optional[QgsEditorWidgetFactory]) – The factory which will create this widget type

Return type:

bool

Returns:

True, if successful, False, if the widgetId is already in use or widgetFactory is None