Class: QgsProcessingParameterString

class qgis.core.QgsProcessingParameterString

Bases: QgsProcessingParameterDefinition

A string parameter for processing algorithms.

A parameter type which allows users to enter any string value.

In some circumstances it is desirable to restrict the values available when a user is asked to enter a string parameter to a list of predetermined “valid” values. Since QGIS 3.22 this can be done by setting the widget wrapper metadata “value_hints” option, as demonstrated below. (While this provides a mechanism for guiding users to select from valid string values when running a Processing algorithm through the GUI, it does not place any limits on the string values accepted via PyQGIS codes or when running the algorithm via other non-gui means. Algorithms should gracefully handle other values accordingly.)

param = QgsProcessingParameterString( 'PRINTER_NAME', 'Printer name')
# show only printers which are available on the current system as options
# for the string input.
param.setMetadata( {'widget_wrapper':
  { 'value_hints': ['Inkjet printer', 'Laser printer'] }
})

New in version 3.0.

QgsProcessingParameterString(name: str, description: str = ‘’, defaultValue: Any = None, multiLine: bool = False, optional: bool = False) Constructor for QgsProcessingParameterString.

QgsProcessingParameterString(QgsProcessingParameterString)

Methods

asPythonString

param outputType

asScriptCode

rtype

str

clone

rtype

QgsProcessingParameterDefinition

fromScriptCode

Creates a new parameter using the definition from a script code.

fromVariantMap

param map

multiLine

Returns True if the parameter allows multiline strings.

setMultiLine

Sets whether the parameter allows multiline strings.

toVariantMap

rtype

Dict[str, Any]

type

rtype

str

typeName

Returns the type name for the parameter class.

valueAsPythonString

param value

asPythonString(self, outputType: QgsProcessing.PythonOutputType = QgsProcessing.PythonQgsProcessingAlgorithmSubclass) str
Parameters

outputType (QgsProcessing.PythonOutputType = QgsProcessing.PythonQgsProcessingAlgorithmSubclass) –

Return type

str

asScriptCode(self) str
Return type

str

clone(self) QgsProcessingParameterDefinition
Return type

QgsProcessingParameterDefinition

fromScriptCode(name: str, description: str, isOptional: bool, definition: str) QgsProcessingParameterString

Creates a new parameter using the definition from a script code.

Parameters
  • name (str) –

  • description (str) –

  • isOptional (bool) –

  • definition (str) –

Return type

QgsProcessingParameterString

fromVariantMap(self, map: Dict[str, Any]) bool
Parameters

map (Dict[str) –

Return type

bool

multiLine(self) bool

Returns True if the parameter allows multiline strings.

See also

setMultiLine()

Return type

bool

setMultiLine(self, multiLine: bool)

Sets whether the parameter allows multiline strings.

See also

multiLine()

Parameters

multiLine (bool) –

toVariantMap(self) Dict[str, Any]
Return type

Dict[str, Any]

type(self) str
Return type

str

typeName() str

Returns the type name for the parameter class.

Return type

str

valueAsPythonString(self, value: Any, context: QgsProcessingContext) str
Parameters
Return type

str