Subgroup: Field
Class: QgsField¶
-
class
qgis.core.
QgsField
¶ Bases:
sip.wrapper
Encapsulate a field in an attribute table or data source. QgsField stores metadata about an attribute field, including name, type length, and if applicable, precision.
Note
QgsField objects are implicitly shared.Methods
alias
Returns the alias for the field (the friendly displayed name of the field ), or an empty string if there is no alias. comment
Returns the field comment constraints
Returns constraints which are present for the field. convertCompatible
Converts the provided variant to a compatible format defaultValueDefinition
Returns the expression used when calculating the default value for the field. displayName
Returns the name to use when displaying this field. displayString
Formats string for display editorWidgetSetup
Get the editor widget setup for the field. isNumeric
Returns if this field is numeric. length
Gets the length of the field. name
Returns the name of the field. precision
Gets the precision of the field. setAlias
Sets the alias for the field (the friendly displayed name of the field ). setComment
Set the field comment setConstraints
Sets constraints which are present for the field. setDefaultValueDefinition
Sets an expression to use when calculating the default value for the field. setEditorWidgetSetup
Set the editor widget setup for the field. setLength
Set the field length. setName
Set the field name. setPrecision
Set the field precision. setSubType
If the field is a collection, set its element’s type. setType
Set variant type. setTypeName
Set the field type. subType
If the field is a collection, gets its element’s type. type
Gets variant type of the field as it will be retrieved from data source typeName
Gets the field type. Attributes
-
alias
(self) → str¶ Returns the alias for the field (the friendly displayed name of the field ), or an empty string if there is no alias.
See also
New in version 3.0.
-
comment
(self) → str¶ Returns the field comment
-
constraints
(self) → QgsFieldConstraints¶ Returns constraints which are present for the field.
New in version 3.0.
See also
-
convertCompatible
(self, v: Any) → bool¶ Converts the provided variant to a compatible format
Parameters: v – The value to convert Returns: True if the conversion was successful
-
defaultValueDefinition
(self) → QgsDefaultValue¶ Returns the expression used when calculating the default value for the field.
Returns: expression evaluated when calculating default values for field, or an empty string if no default is set
New in version 3.0.
See also
-
displayName
(self) → str¶ Returns the name to use when displaying this field. This will be the field alias if set, otherwise the field name.
See also
See also
New in version 3.0.
-
displayString
(self, v: Any) → str¶ Formats string for display
-
editorWidgetSetup
(self) → QgsEditorWidgetSetup¶ Get the editor widget setup for the field.
Defaults may be set by the provider and can be overridden by manual field configuration.
Returns: the value
-
isNumeric
(self) → bool¶ Returns if this field is numeric. Any integer or floating point type will return true for this.
New in version 2.18.
-
length
(self) → int¶ Gets the length of the field.
Returns: int containing the length of the field
-
name
(self) → str¶ Returns the name of the field.
See also
See also
-
precision
(self) → int¶ Gets the precision of the field. Not all field types have a related precision.
Returns: int containing the precision or zero if not applicable to the field type.
-
setAlias
(self, alias: str)¶ Sets the alias for the field (the friendly displayed name of the field ).
Parameters: alias – field alias, or empty string to remove an existing alias See also
New in version 3.0.
-
setComment
(self, comment: str)¶ Set the field comment
-
setConstraints
(self, constraints: QgsFieldConstraints)¶ Sets constraints which are present for the field.
New in version 3.0.
See also
-
setDefaultValueDefinition
(self, defaultValueDefinition: QgsDefaultValue)¶ Sets an expression to use when calculating the default value for the field.
Parameters: defaultValueDefinition – expression to evaluate when calculating default values for field. Pass a default constructed :py:class:`QgsDefaultValue`() to reset.
New in version 3.0.
See also
-
setEditorWidgetSetup
(self, v: QgsEditorWidgetSetup)¶ Set the editor widget setup for the field.
Parameters: v – The value to set
-
setLength
(self, len: int)¶ Set the field length.
Parameters: len – Length of the field
-
setName
(self, name: str)¶ Set the field name.
Parameters: name – Name of the field
-
setPrecision
(self, precision: int)¶ Set the field precision.
Parameters: precision – Precision of the field
-
setSubType
(self, subType: QVariant.Type)¶ If the field is a collection, set its element’s type. When all the elements don’t need to have the same type, set this to QVariant.Invalid.
New in version 3.0.
-
setType
(self, type: QVariant.Type)¶ Set variant type.
-
setTypeName
(self, typeName: str)¶ Set the field type.
Parameters: typeName – Field type
-
subType
(self) → QVariant.Type¶ If the field is a collection, gets its element’s type. When all the elements don’t need to have the same type, this returns QVariant.Invalid.
New in version 3.0.
-
type
(self) → QVariant.Type¶ Gets variant type of the field as it will be retrieved from data source
-
typeName
(self) → str¶ Gets the field type. Field types vary depending on the data source. Examples are char, int, double, blob, geometry, etc. The type is stored exactly as the data store reports it, with no attempt to standardize the value.
Returns: QString containing the field type
-