Class: QgsSearchWidgetWrapper

Shows a search widget on a filter form.

Class Hierarchy

Inheritance diagram of qgis.gui.QgsSearchWidgetWrapper

Base classes

QgsWidgetWrapper

Manages an editor widget Widget and wrapper share the same parent

QObject

Subclasses

QgsCheckboxSearchWidgetWrapper

Wraps a checkbox edit widget for searching.

QgsDateTimeSearchWidgetWrapper

Wraps a date/time edit widget for searching.

QgsDefaultSearchWidgetWrapper

Wraps a search widget. Default form is just a QgsLineFilterEdit

QgsRelationAggregateSearchWidgetWrapper

Search widget for the children of a relation. For each attribute of the child, an additional QgsAggregateToolButton will be shown to determine how the values should be aggregated for searching.

QgsRelationReferenceSearchWidgetWrapper

Wraps a relation reference search widget.

QgsValueMapSearchWidgetWrapper

Wraps a value map search widget. This widget will offer a combobox with values from another layer referenced by a foreign key (a constraint may be set but is not required on data level). It will be used as a search widget and produces expression to look for in the layer.

QgsValueRelationSearchWidgetWrapper

Wraps a value relation search widget. This widget will offer a combobox with values from another layer referenced by a foreign key (a constraint may be set but is not required on data level). It will be used as a search widget and produces expression to look for in the layer.

Methods

aggregate

If in AggregateSearch mode, which aggregate should be used to construct the filter expression.

applyDirectly

If this is True, then this search widget should take effect directly when its expression changes

clearExpression

clears the expression to search for all features

clearWidget

Clears the widget's current value and resets it back to the default state

createExpression

Creates a filter expression based on the current state of the search widget and the specified filter flags.

createFieldIdentifier

Gets a field name or expression to use as field comparison.

defaultFlags

Returns the filter flags which should be set by default for the search widget.

expression

Will be used to access the widget's value.

fieldIndex

Returns the field index

setAggregate

If in AggregateSearch mode, which aggregate should be used to construct the filter expression.

setEnabled

Toggles whether the search widget is enabled or disabled.

setExpression

Set the expression which is currently used as filter for this widget.

supportedFlags

Returns filter flags supported by the search widget.

Static Methods

exclusiveFilterFlags

Returns a list of exclusive filter flags, which cannot be combined with other flags (e.g., EqualTo/NotEqualTo)

nonExclusiveFilterFlags

Returns a list of non-exclusive filter flags, which can be combined with other flags (e.g., CaseInsensitive)

toString

Returns a translated string representing a filter flag.

Signals

expressionChanged

Emitted whenever the expression changes

valueChanged

Emitted when a user changes the value of the search widget.

valueCleared

Emitted when a user changes the value of the search widget back to an empty, default state.

Attributes

Between

CaseInsensitive

Contains

DoesNotContain

EndsWith

EqualTo

GreaterThan

GreaterThanOrEqualTo

IsNotBetween

IsNotNull

IsNull

LessThan

LessThanOrEqualTo

NotEqualTo

StartsWith

class qgis.gui.QgsSearchWidgetWrapper[source]

Bases: QgsWidgetWrapper

__init__(vl: QgsVectorLayer | None, fieldIdx: int, parent: QWidget | None = None)

Create a new widget wrapper

Parameters:
  • vl (Optional[QgsVectorLayer]) – The layer on which the field is

  • fieldIdx (int) – The field which will be controlled

  • parent (Optional[QWidget] = None) – A parent widget for this widget wrapper and the created widget.

Between = 128
CaseInsensitive = 256
Contains = 512
DoesNotContain = 1024
EndsWith = 32768
EqualTo = 2
class FilterFlag

Bases: int

class FilterFlags
class FilterFlags(f: QgsSearchWidgetWrapper.FilterFlags | QgsSearchWidgetWrapper.FilterFlag)
class FilterFlags(a0: QgsSearchWidgetWrapper.FilterFlags)

Bases: object

GreaterThan = 8
GreaterThanOrEqualTo = 32
IsNotBetween = 4096
IsNotNull = 8192
IsNull = 2048
LessThan = 16
LessThanOrEqualTo = 64
NotEqualTo = 4
StartsWith = 16384
aggregate(self) str[source]

If in AggregateSearch mode, which aggregate should be used to construct the filter expression. Is a Null String if none.

Return type:

str

applyDirectly(self) bool[source]

If this is True, then this search widget should take effect directly when its expression changes

Return type:

bool

clearExpression(self)[source]

clears the expression to search for all features

clearWidget(self)[source]

Clears the widget’s current value and resets it back to the default state

createExpression(self, flags: QgsSearchWidgetWrapper.FilterFlags | QgsSearchWidgetWrapper.FilterFlag) str[source]

Creates a filter expression based on the current state of the search widget and the specified filter flags.

Parameters:

flags (Union[QgsSearchWidgetWrapper.FilterFlags, QgsSearchWidgetWrapper.FilterFlag]) – filter flags

Return type:

str

Returns:

filter expression

createFieldIdentifier(self) str[source]

Gets a field name or expression to use as field comparison. If in SearchMode returns a quoted field identifier. If in AggregateSearchMode returns an appropriate aggregate expression.

Return type:

str

defaultFlags(self) QgsSearchWidgetWrapper.FilterFlags[source]

Returns the filter flags which should be set by default for the search widget.

See also

supportedFlags()

Return type:

QgsSearchWidgetWrapper.FilterFlags

static exclusiveFilterFlags() Any

Returns a list of exclusive filter flags, which cannot be combined with other flags (e.g., EqualTo/NotEqualTo)

Return type:

Any

expression(self) str[source]

Will be used to access the widget’s value. Read the value from the widget and return it properly formatted to be saved in the attribute.

If an invalid variant is returned this will be interpreted as no change. Be sure to return a NULL QVariant if it should be set to NULL.

Return type:

str

Returns:

The current value the widget represents

signal expressionChanged(exp: str)[source]

Emitted whenever the expression changes

Parameters:

exp (str) – The new search expression

fieldIndex(self) int[source]

Returns the field index

Added in version 3.10.

Return type:

int

static nonExclusiveFilterFlags() Any

Returns a list of non-exclusive filter flags, which can be combined with other flags (e.g., CaseInsensitive)

Return type:

Any

setAggregate(self, aggregate: str | None)[source]

If in AggregateSearch mode, which aggregate should be used to construct the filter expression. Is a Null String if none.

Parameters:

aggregate (Optional[str])

setEnabled(self, enabled: bool)[source]

Toggles whether the search widget is enabled or disabled.

Parameters:

enabled (bool) – set to True to enable widget

setExpression(self, expression: str | None)[source]

Set the expression which is currently used as filter for this widget.

Parameters:

expression (Optional[str])

supportedFlags(self) QgsSearchWidgetWrapper.FilterFlags[source]

Returns filter flags supported by the search widget.

See also

defaultFlags()

Return type:

QgsSearchWidgetWrapper.FilterFlags

static toString(flag: QgsSearchWidgetWrapper.FilterFlag) str[source]

Returns a translated string representing a filter flag.

Parameters:

flag (QgsSearchWidgetWrapper.FilterFlag) – flag to convert to string

Return type:

str

signal valueChanged[source]

Emitted when a user changes the value of the search widget.

signal valueCleared[source]

Emitted when a user changes the value of the search widget back to an empty, default state.