Subgroup: Conditional

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.
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.

Signals

Attributes

backgroundColor(self) → QColor

The background color for style

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 – The list of styles to compress down
Returns:A single style generated from joining each style property.
displayText(self) → str

The name of the style.

Returns:The name of the style. Names are optional so might be empty.
font(self) → QFont

The font for the style

Returns:QFont for the style
icon(self) → QPixmap

The icon set for style generated from the set symbol

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.

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 – The current value being checked. The “value” variable from the context is replaced with this value.
  • context – Expression context for evaluating rule expression
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.

Returns:A conditional style that matches the value and feature. Check with QgsConditionalStyle.isValid()
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.

Returns:A conditional style that matches the value and feature. Check with QgsConditionalStyle.isValid()
name(self) → str

The name of the style.

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.

renderPreview(self) → QPixmap

Render a preview icon of the rule.

Returns:QPixmap preview of the style
rule(self) → str

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

Returns:QString of the current set rule
setBackgroundColor(self, value: Union[QColor, Qt.GlobalColor, QGradient])

Set the background color for the style

Parameters:value – QColor for background color
setFont(self, value: QFont)

Set the font for the style

Parameters:value – 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 – 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 – 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 to be used when generating the icon
setTextColor(self, value: Union[QColor, Qt.GlobalColor, QGradient])

Set the text color for the style

Parameters:value – QColor for text color
symbol(self) → QgsSymbol

The symbol used to generate the icon for the style

Returns:The QgsSymbol used for the icon
textColor(self) → QColor

The text color set for style

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

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

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.