Class: QgsVariantUtils

Contains utility functions for working with QVariants and QVariant types.

Added in version 3.24.

Static Methods

displayString

Returns a localized representation of value with the given precision, if precision is -1 then precision is guessed from the default QVariant.toString output.

isNull

Returns True if the specified variant should be considered a NULL value.

isNumericType

Returns True if the specified metaType is a numeric type.

typeToDisplayString

Returns a user-friendly translated string representing a QVariant type.

class qgis.core.QgsVariantUtils[source]

Bases: object

static displayString(variant: Any, precision: int = -1) str[source]

Returns a localized representation of value with the given precision, if precision is -1 then precision is guessed from the default QVariant.toString output.

The current localization settings are applied.

For strings, the input text is returned unchanged. For lists, a single string is generated with elements separated by ‘;’.

Note

Precision is ignored for integers.

Added in version 4.0.

Parameters:
  • variant (Any)

  • precision (int = -1)

Return type:

str

static isNull(variant: Any) bool[source]

Returns True if the specified variant should be considered a NULL value.

This method is more rigorous vs QVariant.isNull(), which will return False on newer Qt versions for tests like QVariant( QDateTime() ).isNull().

Added in version 3.28.

Parameters:

variant (Any)

Return type:

bool

static isNumericType(metaType: QMetaType.Type) bool[source]

Returns True if the specified metaType is a numeric type.

Added in version 3.40.

Parameters:

metaType (QMetaType.Type)

Return type:

bool

static typeToDisplayString(type: QMetaType.Type, subType: QMetaType.Type = QMetaType.Type.UnknownType) str[source]

Returns a user-friendly translated string representing a QVariant type.

The optional subType can be used to specify the type of variant list or map values.

Parameters:
  • type (QMetaType.Type)

  • subType (QMetaType.Type = QMetaType.Type.UnknownType)

Return type:

str

static typeToDisplayString(type: QVariant.Type, subType: QVariant.Type = QVariant.Type.Invalid) str[source]

Returns a user-friendly translated string representing a QVariant type.

The optional subType can be used to specify the type of variant list or map values.

Deprecated since version 3.38: Use the method with a QMetaType.Type argument instead.

Parameters:
  • type (QVariant.Type)

  • subType (QVariant.Type = QVariant.Type.Invalid)

Return type:

str