Class: QgsColorUtils¶
- class qgis.core.QgsColorUtils¶
Bases:
sip.wrapper
Contains utility functions for working with colors.
New in version 3.28:
Methods
Decodes a
string
into a color value.Encodes a
color
into a string value.Reads a color from an XML
element
, matching the specifiedidentifier
string.Writes a
color
to an XMLelement
, storing it under the specifiedidentifier
.- colorFromString(string: str) QColor ¶
Decodes a
string
into a color value.This method losslessly retrieves a color’s definition from a string value. All properties of the color are restored, including the color specification and original values of the color’s components. It is therefore suitable for restoring high color depth colors (such as 16 bit colors), or colors using alternative specifications such as CMYK colors.
An invalid color will be returned if the color could not be read.
See also
- Parameters:
string (str) –
- Return type:
QColor
- colorToString(color: QColor | Qt.GlobalColor | QGradient) str ¶
Encodes a
color
into a string value.This method losslessly stores a color’s definition into a single string value. All properties of the color are stored, including the color specification and original values of the color’s components. It is therefore suitable for storing high color depth colors (such as 16 bit colors), or colors using alternative specifications such as CMYK colors.
See also
- Parameters:
color (Union[QColor) –
- Return type:
str
- readXml(element: QDomElement, identifier: str, context: QgsReadWriteContext) QColor ¶
Reads a color from an XML
element
, matching the specifiedidentifier
string.This method losslessly retrieves a color’s definition from an XML element. All properties of the color are restored, including the color specification and original values of the color’s components. It is therefore suitable for restoring high color depth colors (such as 16 bit colors), or colors using alternative specifications such as CMYK colors.
An invalid color will be returned if the color could not be read.
See also
- Parameters:
element (QDomElement) –
identifier (str) –
context (QgsReadWriteContext) –
- Return type:
QColor
- writeXml(color: QColor | Qt.GlobalColor | QGradient, identifier: str, document: QDomDocument, element: QDomElement, context: QgsReadWriteContext)¶
Writes a
color
to an XMLelement
, storing it under the specifiedidentifier
.This method losslessly stores a color’s definition in an XML
element
. All properties of the color are stored, including the color specification and original values of the color’s components. It is therefore suitable for storing high color depth colors (such as 16 bit colors), or colors using alternative specifications such as CMYK colors.The
identifier
string is used to specify the element name for the stored color, allowing for multiple color definitions to be stored in a singleelement
(assuming each uses a unique identifier string).See also
- Parameters:
color (Union[QColor) –
identifier (str) –
document (QDomDocument) –
element (QDomElement) –
context (QgsReadWriteContext) –