Class: QgsConditionalStyle

class qgis.core.QgsConditionalStyle

Bases: sip.wrapper

Conditional styling for a rule.

Methods

backgroundColor

The background color for style

compressStyles

Compress a list of styles into a single style.

displayText

The name of the style.

font

The font for the style

icon

The icon set for style generated from the set symbol

isValid

isValid Check if this rule is valid.

matches

Check if the rule matches using the given value and feature

matchingConditionalStyle

Find and return the matching style for the value and feature.

matchingConditionalStyles

Find and return the matching styles for the value and feature.

name

The name of the style.

readXml

Reads vector conditional style specific state from layer Dom node.

renderPreview

Render a preview icon of the rule, at the specified size.

rule

The condition rule set for the style.

setBackgroundColor

Set the background color for the style

setFont

Set the font for the style

setName

Set the name of the style.

setRule

Set the rule for the style.

setSymbol

Set the icon for the style.

setTextColor

Set the text color for the style

symbol

The symbol used to generate the icon for the style

textColor

The text color set for style

validBackgroundColor

Check if the background color is valid for render.

validTextColor

Check if the text color is valid for render.

writeXml

Write vector conditional style specific state from layer Dom node.

backgroundColor(self)QColor

The background color for style

Return type

QColor

Returns

QColor for background color

compressStyles(styles: Iterable[QgsConditionalStyle])QgsConditionalStyle

Compress a list of styles into a single style. This can be used to stack the elements of the styles. The font of the last style is used in the output.

Parameters

styles (Iterable[QgsConditionalStyle]) – The list of styles to compress down

Return type

QgsConditionalStyle

Returns

A single style generated from joining each style property.

displayText(self)str

The name of the style.

Return type

str

Returns

The name of the style. Names are optional so might be empty.

font(self)QFont

The font for the style

Return type

QFont

Returns

QFont for the style

icon(self)QPixmap

The icon set for style generated from the set symbol

Return type

QPixmap

Returns

A QPixmap that was set for the icon using the symbol

isValid(self)bool

isValid Check if this rule is valid. A valid rule has one or more properties set.

Return type

bool

Returns

True if the rule is valid.

matches(self, value: Any, context: QgsExpressionContext)bool

Check if the rule matches using the given value and feature

Parameters
  • value (Any) – The current value being checked. The “value” variable from the context is replaced with this value.

  • context (QgsExpressionContext) – Expression context for evaluating rule expression

Return type

bool

Returns

True of the rule matches against the given feature

matchingConditionalStyle(styles: Iterable[QgsConditionalStyle], value: Any, context: QgsExpressionContext)QgsConditionalStyle

Find and return the matching style for the value and feature. If no match is found a invalid QgsConditionalStyle is return.

Return type

QgsConditionalStyle

Returns

A conditional style that matches the value and feature. Check with QgsConditionalStyle.isValid()

Parameters
matchingConditionalStyles(styles: Iterable[QgsConditionalStyle], value: Any, context: QgsExpressionContext)List[QgsConditionalStyle]

Find and return the matching styles for the value and feature. If no match is found a invalid QgsConditionalStyle is return.

Return type

List[QgsConditionalStyle]

Returns

A conditional style that matches the value and feature. Check with QgsConditionalStyle.isValid()

Parameters
name(self)str

The name of the style.

Return type

str

Returns

The name of the style. Names are optional so might be empty.

readXml(self, node: QDomNode, context: QgsReadWriteContext)bool

Reads vector conditional style specific state from layer Dom node.

Parameters
Return type

bool

renderPreview(self, size: QSize = QSize())QPixmap

Render a preview icon of the rule, at the specified size.

If size is not specified, a default size will be used.

Return type

QPixmap

Returns

QPixmap preview of the style

Parameters

size (QSize = QSize()) –

rule(self)str

The condition rule set for the style. Rule may contain variable @value to represent the current value

Return type

str

Returns

QString of the current set rule

setBackgroundColor(self, value: Union[QColor, Qt.GlobalColor, QGradient])

Set the background color for the style

Parameters

value (Union[QColor) – QColor for background color

setFont(self, value: QFont)

Set the font for the style

Parameters

value (QFont) – QFont to be used for text

setName(self, value: str)

Set the name of the style. Names are optional but handy for display

Parameters

value (str) – The name given to the style

setRule(self, value: str)

Set the rule for the style. Rules should be of QgsExpression syntax. Special value of @value is replaced at run time with the check value

Parameters

value (str) – The QgsExpression style rule to use for this style

setSymbol(self, value: QgsSymbol)

Set the icon for the style. Icons are generated from symbols

Parameters

value (QgsSymbol) – QgsSymbol to be used when generating the icon

setTextColor(self, value: Union[QColor, Qt.GlobalColor, QGradient])

Set the text color for the style

Parameters

value (Union[QColor) – QColor for text color

symbol(self)QgsSymbol

The symbol used to generate the icon for the style

Return type

QgsSymbol

Returns

The QgsSymbol used for the icon

textColor(self)QColor

The text color set for style

Return type

QColor

Returns

QColor for text color

validBackgroundColor(self)bool

Check if the background color is valid for render. Valid colors are non invalid QColors and a color with a > 0 alpha

Return type

bool

Returns

True of the color set for background is valid.

validTextColor(self)bool

Check if the text color is valid for render. Valid colors are non invalid QColors and a color with a > 0 alpha

Return type

bool

Returns

True of the color set for text is valid.

writeXml(self, node: QDomNode, doc: QDomDocument, context: QgsReadWriteContext)bool

Write vector conditional style specific state from layer Dom node.

Parameters
Return type

bool