Class: QgsEditorWidgetFactory

class qgis.gui.QgsEditorWidgetFactory

Bases: sip.wrapper

Every attribute editor widget needs a factory, which inherits this class

It provides metadata for the widgets such as the name (human readable), it serializes the configuration to an xml structure and loads the configuration from there.

It also has factory methods to create a widget wrapper for the attribute editor itself and another factory method to create a configuration dialog.

QgsEditorWidgetFactory(name: str) Constructor

Parameters:

name – A human readable name for this widget type

QgsEditorWidgetFactory(QgsEditorWidgetFactory)

Methods

configWidget

Override this in your implementation.

create

Override this in your implementation.

createSearchWidget

param vl:

fieldScore

This method allows disabling this editor widget type for a certain field.

name

Returns The human readable identifier name of this widget type

supportsField

Check if this editor widget type supports a certain field.

configWidget(self, vl: QgsVectorLayer, fieldIdx: int, parent: QWidget) QgsEditorConfigWidget

Override this in your implementation. Create a new configuration widget for this widget type.

Parameters:
  • vl (QgsVectorLayer) – The layer for which the widget will be created

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

  • parent (QWidget) – The parent widget of the created config widget

Return type:

QgsEditorConfigWidget

Returns:

A configuration widget

create(self, vl: QgsVectorLayer, fieldIdx: int, editor: QWidget, parent: QWidget) QgsEditorWidgetWrapper

Override this in your implementation. Create a new editor widget wrapper. Call QgsEditorWidgetRegistry.create() instead of calling this method directly.

Parameters:
  • vl (QgsVectorLayer) – The vector layer on which this widget will act

  • fieldIdx (int) – The field index on which this widget will act

  • editor (QWidget) – An editor widget if already existent. If None is provided, a new widget will be created.

  • parent (QWidget) – The parent for the wrapper class and any created widget.

Return type:

QgsEditorWidgetWrapper

Returns:

A new widget wrapper

createSearchWidget(self, vl: QgsVectorLayer, fieldIdx: int, parent: QWidget) QgsSearchWidgetWrapper
Parameters:
Return type:

QgsSearchWidgetWrapper

fieldScore(self, vl: QgsVectorLayer, fieldIdx: int) int

This method allows disabling this editor widget type for a certain field. By default, it returns 5 for every fields. Reimplement this if you only support certain fields.

Typical return values are:

  • 0: not supported

  • 5: maybe support (for example, Datetime support strings depending on their content)

  • 10: basic support (this is what returns TextEdit for example, since it supports everything in a crude way)

  • 20: specialized support

Parameters:
Return type:

int

Returns:

0 if the field is not supported or a bigger number if it can (the widget with the biggest number will be taken by default). The default implementation returns 5..

See also

supportsField()

name(self) str

Returns The human readable identifier name of this widget type

Return type:

str

Returns:

a name

supportsField(self, vl: QgsVectorLayer, fieldIdx: int) bool

Check if this editor widget type supports a certain field.

Parameters:
  • vl (QgsVectorLayer) – The layer

  • fieldIdx (int) – The field index

Return type:

bool

Returns:

True if the type is supported for this field

See also

fieldScore()