CDPBaseLabel Class
| Header: | #include <CDPBaseWidgets/CDPBaseLabel.h> |
| Inherits: | StateChanger, CDPBaseCom, CDPBaseControlVisible, |
| Inherited By: |
Public Types
| enum | NumForm { Normal, Scientific, MixedMode } |
| typedef | StylingSvgMap |
| enum | StylingType { NoFile, CSS, SVG, General, ..., Unit } |
Properties
|
|
Public Functions
| CDPBaseLabel(QWidget *parent = 0) | |
| virtual | ~CDPBaseLabel() |
| QString | cdpStyle() |
| QString | cssFile() |
| bool | cssFileDisabled() |
| QColor | fontColor() |
| StylingType | getStylingType() |
| bool | isCssStyling() |
| bool | isSvgStyling() |
| bool | noSystemBackground() |
| NumForm | numFormat() |
| bool | opaquePaintEvent() |
| QString | postfix() |
| int | precision() |
| QString | routing() |
| void | setCdpStyle(QString routing) |
| void | setCssFile(QString cssFile, bool updateTheme = true) |
| virtual void | setIQtCDPPointer(IQtCDP *pIQtCDP) |
| void | setNoSystemBackground(bool enable) |
| void | setNumFormat(NumForm format) |
| void | setOpaquePaintEvent(bool enable) |
| void | setPostfix(QString pfix) |
| void | setPrecision(int value) |
| void | setStylingType(StylingType type) |
| void | setSvgFile(const QString &svg) |
| virtual void | setTextFromProperty(QString propertyValue) |
| QString | svgFile() |
- 3 public functions inherited from StateChanger
- 14 public functions inherited from CDPBaseCom
- 4 public functions inherited from CDPBaseControlVisible
Public Slots
| virtual void | handleVisible(double visible) |
| virtual void | hideWidget() |
| virtual void | setFontColor(QColor fontColor) |
| virtual void | setInCommand(bool cmd) |
| void | setRouting(QString routing) |
| virtual void | setSmoothPixmap(bool smooth) |
| virtual void | setValue(double value) |
| virtual void | setValue(int value) |
| virtual void | setValue(bool value) |
| virtual void | setValue(const QString &value) |
| virtual bool | setValue(QString value, bool bScale) |
| virtual void | setWidgetFont(const QString &font) |
| virtual void | setWidgetStyle(double style) |
| virtual void | setWidgetStyle(int style) |
| virtual void | setWidgetTheme(const QString &theme) |
| virtual void | showWidget() |
| virtual int | widgetStyle() |
Signals
Protected Functions
| QString | addUrl(QString path) |
| QString | generatedStyleSheet() |
| void | loadSvg() |
| virtual void | mousePressEvent(QMouseEvent *e) |
| virtual void | mouseReleaseEvent(QMouseEvent *e) |
| void | processSvgFile(QString svg) |
| void | updateTextColorFromSvg() |
- 4 protected functions inherited from CDPBaseCom
- 1 protected function inherited from CDPBaseControlVisible
Detailed Description

The Label widget main function is to display plain text or a CDP object/property.
To enter a text to be displayed, double click on the widget and type the text or use the text property.
To show the text or numeric value of a CDP object/property, enter the path in the cdpRouting property.
The Label must be used to display all texts and values in a GUI to enable elements like titles, sub-titles, information and values to show correctly in all themes. For instance, one theme might have left-aligned titles while another might have the titles centered.
The stylingType property allows styling text and values consistently in the GUI according to selected theme. Pre-defined styles exist for title, sub-title, plain text, values and units.
The cdpScaling property is used to scale the value that is displayed. E.g. if a signal in the system is in meter, we can set cdpScaling to 0.001 if we rather want it to display in km.
The postfix property is used to add a text after the actual value. E.g. to add the word “bar” behind a pressure reading, set postfix to “ bar”.
The Label also has lots of other properties to explore. Like options for styling, setting min/max size, layout size policies, number precision etc.
Styling by SVG
The Label is usually styled by selecting one of the predefined types in the stylingType property, like Title, Value, Unit etc. Selecting one of these types will read the styling from a general theme SVG file, located in "themes/${theme_name}/general/theme.svg". The structure of the theme.svg file is not similar to the one used when setting stylingType to SVG and providing a SVG file in the svgFile property. That one uses the same styling as the Line Edit as described in the bottom of this section. The theme.svg file has the following SVG structure.
svg └─── Layer1 ├─── cdpValuePostfix (text) ├─── cdpValue (text) ├─── cdpSubHeading (text) ├─── cdpTitle (text) ├─── cdpFontColorUnit (text) ├─── cdpFontColorMain (text) └─── cdpFontColorMainInv (text)
The following table explains the named elements in more detail. Note that some of them are not relevant for the Label.
| Property | Type | Description |
|---|---|---|
| cdpValuePostfix | text | The color, size and family of the font to be used when setting stylingType to Unit. |
| cdpValue | Transparent rect/path | The color, size and family of the font to be used when setting stylingType to Value. |
| cdpSubHeading | text | The color, size and family of the font to be used when setting stylingType to SubHeading. This property also provides text alignment by checking if the text in the SVG element contains AlignLeft, AlignRight, AlignCenter, AlignVCenter and/or AlignHCenter. The default is horizontal and vertical centered text. |
| cdpTitle | text | The color, size and family of the font to be used when setting stylingType to Title. Similar to cdpSubHeading, it also sets the text alignment. A common use case for the Title is when placing labels as a top titles in containers. |
| cdpFontColorUnit | text | This color element is currently not in use by any CDP widget, but this might change in the future. |
| cdpFontColorMain | text | The color of the font to be used when setting stylingType to General. |
| cdpFontColorMainInv | text | This color element is currently not in use by any CDP widget, but this might change in the future. |
When not styling using the general theme file, the svgFile property can be used to style the widget. Styling by SVG enables switching between different themes in runtime (as long as the files are placed at identical locations within theme directories).
The CDPBaseLabel supports reading both background image and text color from SVG similar to that of CDPBaseLineEdit described here. To enable the background to show on the label we have to make sure that the property named noSystemBackground is set to false.
Note: The SVG doesn't have to include background image though it is supported, but when present, the widget will generate raster images as described here.
Member Type Documentation
enum CDPBaseLabel::NumForm
This enum type specifies how to format numbers:
| Constant | Value | Description |
|---|---|---|
CDPBaseLabel::Normal | 1 | Format as [-]9.9 |
CDPBaseLabel::Scientific | 2 | Format as [-]9.9e[+|-]999 |
CDPBaseLabel::MixedMode | 3 | Use "Normal" or "Scientific" format, whichever is the most concise. |
typedef CDPBaseLabel::StylingSvgMap
enum CDPBaseLabel::StylingType
This enum type specifies a styling type:
| Constant | Value | Description |
|---|---|---|
CDPBaseLabel::NoFile | 0 | No custom styling (enables styleSheet property). |
CDPBaseLabel::CSS | 1 | Style by CSS file (enables cssFile property). |
CDPBaseLabel::SVG | 2 | Style by SVG file (enables svgFile property). |
CDPBaseLabel::General | 3 | Generates stylesheet with color. |
CDPBaseLabel::Value | 6 | Value text styling as provided by general theme SVG. |
CDPBaseLabel::SubHeading | 5 | Sub heading text styling as provided by general theme SVG. |
CDPBaseLabel::Main | 8 | Main contents text styling as provided by general theme SVG. |
CDPBaseLabel::Title | 4 | Title text styling as provided by general theme SVG. |
CDPBaseLabel::Unit | 7 | Value unit text styling as provided by general theme SVG. |
Property Documentation
cdpRouting : QString
This property holds the routing to the cdp object we want connect to.
Access functions:
| QString | routing() |
| void | setRouting(QString routing) |
cdpScaling : const double
This property holds a value with which the decimal (if present) value is multiplied.
This works with both signals and properties.
cdpStyleRouting : QString
This property holds the routing to the cdp object that is used to change the widget svg style.
Access functions:
| QString | cdpStyle() |
| void | setCdpStyle(QString routing) |
cdpVisibleRouting : const QString
This property holds the full path of the signal/parameter that controls the “visible” property.
Note: Values not equal to 1 are considered false.
See also visible.
cssFile : QString
This property holds the css file to use for customization.
http://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qspinbox
Access functions:
| QString | cssFile() |
| void | setCssFile(QString cssFile, bool updateTheme = true) |
See also svgFile.
fontColor : QColor
This property holds the font color.
Note: If set, this overrides the text color from SVG file and the entire code received from CSS file.
Access functions:
| QColor | fontColor() |
| virtual void | setFontColor(QColor fontColor) |
noSystemBackground : bool
This property holds whether the widget has a background.
Newly exposed areas are never filled with the background.
Access functions:
| bool | noSystemBackground() |
| void | setNoSystemBackground(bool enable) |
See also opaquePaintEvent.
numFormat : NumForm
This property holds the format in which numbers are displayed.
Access functions:
| NumForm | numFormat() |
| void | setNumFormat(NumForm format) |
See also precision.
opaquePaintEvent : bool
This property holds whether the widget is transparent.
Set true to optimize painting when having no transparency in widget graphics This property should be set true on all widgets that does not require transparency. It will prevent Qt from painting widgets behind current widget and thus increase performance.
Access functions:
| bool | opaquePaintEvent() |
| void | setOpaquePaintEvent(bool enable) |
See also visible, cdpVisibleRouting, and noSystemBackground.
postfix : QString
This property holds the string that is appended to the displayed value.
Access functions:
| QString | postfix() |
| void | setPostfix(QString pfix) |
precision : int
This property holds the value of decimal places for numbers.
Sets the number of decimals to show when displaying fractured numbers or number of decimal notations before switching to scientific display in “MixedMode”
Access functions:
| int | precision() |
| void | setPrecision(int value) |
See also numFormat.
stylingType : StylingType
This property holds a selection of how to customize the widget.
Note: All styles can be overridden by fontColor.
Access functions:
| StylingType | getStylingType() |
| void | setStylingType(StylingType type) |
svgFile : QString
This property holds the svg file to use for customization.
Access functions:
| QString | svgFile() |
| void | setSvgFile(const QString &svg) |
See also cssFile and noSystemBackground.
visible : const bool
This property holds whether to show the QWidget or not.
See also cdpVisibleRouting.
widgetStyle : int
This property holds the widget style to use in the svg file.
Note: This will only have effect if the svg file provides styles.
Access functions:
| virtual int | widgetStyle() |
| virtual void | setWidgetStyle(double style) |
| virtual void | setWidgetStyle(int style) |
See also stylingType.
Member Function Documentation
CDPBaseLabel::CDPBaseLabel(QWidget *parent = 0)
Default constructs an instance of CDPBaseLabel.
[virtual] CDPBaseLabel::~CDPBaseLabel()
Destroys the instance of CDPBaseLabel. The destructor is virtual.
[protected] QString CDPBaseLabel::addUrl(QString path)
[signal] void CDPBaseLabel::clicked()
bool CDPBaseLabel::cssFileDisabled()
[protected] QString CDPBaseLabel::generatedStyleSheet()
[virtual slot] void CDPBaseLabel::handleVisible(double visible)
[virtual slot] void CDPBaseLabel::hideWidget()
bool CDPBaseLabel::isCssStyling()
bool CDPBaseLabel::isSvgStyling()
[protected] void CDPBaseLabel::loadSvg()
[virtual protected] void CDPBaseLabel::mousePressEvent(QMouseEvent *e)
[virtual protected] void CDPBaseLabel::mouseReleaseEvent(QMouseEvent *e)
[signal] void CDPBaseLabel::pressed()
[protected] void CDPBaseLabel::processSvgFile(QString svg)
[signal] void CDPBaseLabel::released()
[virtual] void CDPBaseLabel::setIQtCDPPointer(IQtCDP *pIQtCDP)
[virtual slot] void CDPBaseLabel::setInCommand(bool cmd)
[virtual slot] void CDPBaseLabel::setSmoothPixmap(bool smooth)
[virtual] void CDPBaseLabel::setTextFromProperty(QString propertyValue)
[virtual slot] void CDPBaseLabel::setValue(double value)
[virtual slot] void CDPBaseLabel::setValue(int value)
[virtual slot] void CDPBaseLabel::setValue(bool value)
[virtual slot] void CDPBaseLabel::setValue(const QString &value)
[virtual slot] bool CDPBaseLabel::setValue(QString value, bool bScale)
[virtual slot] void CDPBaseLabel::setWidgetFont(const QString &font)
[virtual slot] void CDPBaseLabel::setWidgetTheme(const QString &theme)
[virtual slot] void CDPBaseLabel::showWidget()
[protected] void CDPBaseLabel::updateTextColorFromSvg()
Get started with CDP Studio today
Let us help you take your great ideas and turn them into the products your customer will love.