Conditional Formatting

This feature enables dynamic, data-driven text styles in reports, based on the current value of any data source column, parameter, variable, or script expression. Conditional formatting is available for Labels and Fields only. (HTML Text items can be styled dynamically in a different way: by embedding data references or script expressions in the HTML code in template mode.)

The format definition is a block of code with style tags and values or expressions, similar to CSS code. A style tag and its value/expression are separated by a colon, and each line contains one style definition. A value can be a constant, a data source, parameter, or variable reference, or a script expression. Script expressions must be enclosed in curly braces: if the value starts with {, it is evaluated as a script.

Dynamic Style Tag Symbols

Tag symbol

Description

Examples

color:

Text foreground color

color:#ff0000, color:$D{ds.color}, color:{if($D{ds.price}>500) "#ff0000"; else "";}

background-color:

Text background color

background-color:#ff0000, background-color:$D{ds.bgcolor}

font-family:

Font family name

font-family:Arial, font-family:$D{ds.font}

font-bold:

Font bold on/off

font-bold:true, font-bold:$D{ds.isBold}

font-italic:

Font italic on/off

font-italic:true, font-italic:$D{ds.isItalic}

font-weight:

Font weight integer value. Higher value results in bolder text.

font-weight:50, font-weight:$D{ds.fweight}

font-underline:

Font underline on/off

font-underline:true, font-underline:$D{ds.isUnderline}

font-size:

Font size in points. Integer value.

font-size:12, font-size:$D{ds.size}

font-strikeout:

Font strikeout on/off

font-strikeout:true, font-strikeout:$D{ds.fstrikeout}

letter-spacing:

Text letter spacing value. A greater value results in wider spacing.

letter-spacing:1.5, letter-spacing:$D{ds.letterspacing}

capitalization:

Rendering option that the text font applies. Integer value from 0 to 4. Equals the QFont::Capitalization enumeration property.

capitalization:$D{ds.cap}

Editing Style Code in Designer

To define conditional text formatting for a Label or a Field, click the Conditional formatting…​ button at the bottom of the item property dialog. The conditional format code dialog appears. Type or paste the format code, following the syntax rules, then click OK to save the code.

conditional format
NOTE

A style tag and its value must be on one line. A style definition split across multiple lines is not evaluated. Since the first colon separates the tag from its value, the value itself must not contain a colon.

Default Style

If a condition (script or data) returns an empty value, the default style is applied. The default style settings are the ones you set statically in the report, as usual.

Examples

The CondFormatDemo.xml, CondFormatDemo_JS.xml, and CondFormatDemo2.xml demo reports show conditional formatting in practice.

Conditional format code can also modify the value of variables. See Modifying variables.