Class: QgsConditionalStyle

Conditional styling for a rule.

class qgis.core.QgsConditionalStyle[source]

Bases: object

backgroundColor(self) QColor[source]

The background color for style

Return type:

QColor

Returns:

QColor for background color

static compressStyles(styles: Iterable[QgsConditionalStyle]) QgsConditionalStyle[source]

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[source]

The name of the style.

Return type:

str

Returns:

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

font(self) QFont[source]

The font for the style

Return type:

QFont

Returns:

QFont for the style

icon(self) QPixmap[source]

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[source]

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[source]

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

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

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:
static 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[source]

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[source]

Reads vector conditional style specific state from layer Dom node.

Parameters:
Return type:

bool

renderPreview(self, size: QSize = QSize()) QPixmap[source]

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[source]

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

Return type:

str

Returns:

string of the current set rule

setBackgroundColor(self, value: QColor | Qt.GlobalColor)[source]

Set the background color for the style

Parameters:

value (Union[QColor, Qt.GlobalColor]) – QColor for background color

setFont(self, value: QFont)[source]

Set the font for the style

Parameters:

value (QFont) – QFont to be used for text

setName(self, value: str | None)[source]

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

Parameters:

value (Optional[str]) – The name given to the style

setRule(self, value: str | None)[source]

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 (Optional[str]) – The QgsExpression style rule to use for this style

setSymbol(self, value: QgsSymbol | None)[source]

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

Parameters:

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

setTextColor(self, value: QColor | Qt.GlobalColor)[source]

Set the text color for the style

Parameters:

value (Union[QColor, Qt.GlobalColor]) – QColor for text color

symbol(self) QgsSymbol | None[source]

The symbol used to generate the icon for the style

Return type:

Optional[QgsSymbol]

Returns:

The QgsSymbol used for the icon

textColor(self) QColor[source]

The text color set for style

Return type:

QColor

Returns:

QColor for text color

validBackgroundColor(self) bool[source]

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[source]

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[source]

Write vector conditional style specific state from layer Dom node.

Parameters:
Return type:

bool