• Skip to main content
  • Skip to header right navigation
  • Skip to site footer
CDP Studio logo

CDP Studio

The no-code and full-code software development tool for distributed control systems and HMI

  • Doc
  • Why CDP
    • Software developers
    • Automation engineers
    • Managers
  • Products
    • Automation Designer
    • HMI Designer
    • Maritime HMIs
  • Services
  • Use cases
  • Pricing
  • Try CDP

CDP Studio Documentation

  • GUI - CDP Widgets
  • CDPBasePicture

CDPBasePicture Class

The Picture widget can show raster images/pixmaps and scalable vector graphics (.svg). More...

Header: #include <CDPBasePicture>
Inherits: CDPBaseWidget, RoutingContainerBase, and
Inherited By:

CDPBaseLine and CDPBasePictureSequence

  • List of all members, including inherited members

Properties

  • alignment : Qt::Alignment
  • cdpFullTargetRouting : const QString
  • cdpHeightRouting : QString
  • cdpPosCenter : bool
  • cdpPosRelative : bool
  • cdpPosXRouting : QString
  • cdpPosYRouting : QString
  • cdpRotationRouting : QString
  • cdpStyleRouting : QString
  • cdpTargetRouting : QString
  • cdpWidthRouting : QString
  • lockAspectRatio : bool
  • minimumSizeHint : bool
  • pixmap : QPixmap
  • rotation : int
  • rotationVertical : bool
  • scaledContents : bool
  • svgFile : QString
  • 6 properties inherited from CDPBaseWidget

Public Functions

CDPBasePicture(QWidget *parent = 0)
void addWidget(QWidget *widget, const QString &title = "") override
virtual Qt::Alignment alignment()
QString cdpHeightRouting()
virtual bool cdpPosCenter()
virtual bool cdpPosRelative()
QString cdpPosXRouting()
QString cdpPosYRouting()
QString cdpRotationRouting()
QString cdpStyle()
QString cdpWidthRouting()
virtual bool lockAspectRatio() const
virtual bool minSizeHintEnabled() const
double paddingAdjustedRelativePosition(double pos, bool horizontal) const
virtual const QPixmap &pixmap()
void removeWidgets() override
virtual int rotation()
virtual bool rotationVertical()
virtual bool scaledContents() const
virtual void setAlignment(Qt::Alignment alignment)
virtual void setCdpPosCenter(bool enable)
virtual void setCdpPosRelative(bool enable)
void setCdpPosXRouting(QString routing)
void setCdpPosYRouting(QString routing)
void setCdpRotationRouting(QString routing)
void setCdpStyle(QString routing)
void setHeightRouting(const QString &routing)
virtual void setMinSizeHint(bool enable)
virtual void setPixmap(const QPixmap &pixmap)
virtual void setRotationVertical(bool enable)
virtual void setSvgFile(const QString &svg)
void setWidthRouting(const QString &routing)
QSize sizeHint() const override
virtual QString svgFile() const

Reimplemented Public Functions

virtual void setIQtCDPPointer(IQtCDP *pIQtCDP) override
  • 8 public functions inherited from CDPBaseWidget
  • 3 public functions inherited from RoutingContainerBase
  • 4 public functions inherited from CDPBaseControlVisible

Public Slots

virtual void forceWidgetStyle(int style)
virtual void forceWidgetStyle(double style)
virtual void setCdpTargetRouting(const QString &routing) override
virtual void setLockAspectRatio(bool enable)
virtual void setPosX(double posX)
virtual void setPosX(int posX)
virtual void setPosY(double posY)
virtual void setPosY(int posY)
virtual void setRelativePosX(double posX)
virtual void setRelativePosY(double posY)
virtual void setRotation(int rotation)
virtual void setRotation(double rotation)
virtual void setScaledContents(bool enable)
virtual void setWidgetStyle(int style)
virtual void setWidgetTheme(const QString &theme)
  • 10 public slots inherited from CDPBaseWidget

Signals

void clicked()
void pressed()
  • 1 signal inherited from CDPBaseWidget

Protected Functions

QWidget *canvasWidget() const
QWidget *convertToLoaderWidget(QWidget *widget) const
bool eventFilter(QObject *watched, QEvent *event) override
void initPixmap(QSize pixSize)
virtual void loadSvg()
virtual QSize minimumSizeHint() const
void mousePressEvent(QMouseEvent *ev) override
void mouseReleaseEvent(QMouseEvent *ev) override
void paintEvent(QPaintEvent *ev) override
QRect pixmapRect() const
QSize pixmapTargetSize(const QSize &pixSize) const
virtual void processSvgFile(QString svg)
QPoint rectPos(const QRect &rect) const
void resizeEvent(QResizeEvent *ev) override
  • 1 protected function inherited from CDPBaseControlVisible

Protected Slots

void initDeprecated()

Additional Inherited Members

  • 3 static public members inherited from RoutingContainerBase

Detailed Description

The Picture widget can show raster images/pixmaps and scalable vector graphics (.svg).

There are several properties that can be used to display the picture depending on picture type and usage. Aspect ratio can be toggled on/off and there are properties for scaling and aligning the picture inside the widget when picture has a fixed size. The picture can also be rotated and have a minimum size hint (when used in layouts) as described in the following table.

NameDescription
alignmentAlign the picture within the widget (will have no effect when scaledContents is true and lockAspectRatio is false).
scaledContentsEnable this property to make the picture scalable.
lockAspectRatioEnable this property to lock the original aspect ratio (will only have effect when scaledContents is enabled).
minimumSizeHintEnable minimum size hint (will adjust size when used in layouts).
rotationSet to rotate the image ( angle in degrees ).

The Picture widgets have several properties to enable animations and control from CDP objects/properties. Adding routing to one or more of the following properties will allow switching style, position and rotation.

NameDescription
cdpPosRelativeThis property holds whether to set routed positions in pixels or as factors relative to parent size.
cdpPosXRouting This property holds the routing to the CDP object/property that is to control picture x position.
cdpPosYRoutingThis property holds the routing to the CDP object/property that is to control picture y position.
cdpRotationRoutingThis property holds the routing to the CDP object/property that is to control the rotation of the picture.
cdpStyleRoutingThis property holds the routing to the CDP object/property that is to control which style element in the SVG file to show.

The above properties provide a straightforward way to, for instance, place images on a map, making it easy to show things like ship locations. When you're not sure how many objects/nodes you need to display, you can employ the Node Container to enable real-time picture updating.

Note: Using the property named pixmap instead of the svgFile might result in a pixelated end result, and will ignore properties related to styling.

Styling by SVG

Use the svgFile property to style the widget using a svg file. Styling by svg enables switching between different themes in runtime (as long as the files are placed at identical locations within theme directories).

Main element structure

The structure of the svg is currently very simple and not really necessary. Users should consider using an ordinary svg without thinking about the structure. Note however, that the widget support styles and can thus be used as a picture sequence.

svg
└─── Layer1
      └─── cdpPicture        (element group)
            ├─── < Path >    (transparent rect/path)
            └─── < Group >   (graphics)

The following table explains the named elements in more detail.

PropertyTypeDescription
cdpPicturerect or an element group containing a rectThe cdpPicture should contain the actual background graphics. To ensure that the svg parser gets the correct size (and aspect ratio), we have to place a transparent rect along with the graphics within a group element.

Style element structure

The picture also supports styles that can be changed by the widgetStyle property or by cdp signal/object. Styles makes it possible to use the widget as a picture sequence.

svg
├─── Layer1
│     └─── ...                (see previous section)
└─── Styles
      └─── cdpPictureStyleX   (element group)
               ├─── < Path >  (transparent rect/path)
               └─── < Group > (graphics)

Property Documentation

alignment : Qt::Alignment

Align the picture within the widget (will have no effect when scaledContents is true and lockAspectRatio is false).

Access functions:

virtual Qt::Alignment alignment()
virtual void setAlignment(Qt::Alignment alignment)

cdpFullTargetRouting : const QString

cdpHeightRouting : QString

This property holds routing to control the widget height.

Access functions:

QString cdpHeightRouting()
void setHeightRouting(const QString &routing)

cdpPosCenter : bool

This property holds whether to position the widget relative to its center or top left corner.

Enabling this feature and setting position (0,0) will show the picture in the top left corner of its parent, but as it is positioned on center, only the bottom right corner of the picture will be visible. Further, having the center option disabled will ensure that the entire picture always shows as long as position is set between (0,0) and the (height, width) of the parent.

Access functions:

virtual bool cdpPosCenter()
virtual void setCdpPosCenter(bool enable)

cdpPosRelative : bool

This property holds whether to set routed positions in pixels or as factors relative to parent size.

Access functions:

virtual bool cdpPosRelative()
virtual void setCdpPosRelative(bool enable)

cdpPosXRouting : QString

This property holds the routing to the object that is to control x position.

Access functions:

QString cdpPosXRouting()
void setCdpPosXRouting(QString routing)

cdpPosYRouting : QString

This property holds the routing to the object that is to control y position.

Access functions:

QString cdpPosYRouting()
void setCdpPosYRouting(QString routing)

cdpRotationRouting : QString

This property holds the routing to the CDP object/property that is to control the rotation of the picture.

Access functions:

QString cdpRotationRouting()
void setCdpRotationRouting(QString routing)

cdpStyleRouting : QString

Set the routing of the CDP object that is to change the widget svg style.

Access functions:

QString cdpStyle()
void setCdpStyle(QString routing)

cdpTargetRouting : QString

Access functions:

virtual void setCdpTargetRouting(const QString &routing) override

cdpWidthRouting : QString

This property holds routing to control the widget width.

Access functions:

QString cdpWidthRouting()
void setWidthRouting(const QString &routing)

lockAspectRatio : bool

Enable this property to lock the original aspect ratio (will only have effect when scaledContents is enabled).

Access functions:

virtual bool lockAspectRatio() const
virtual void setLockAspectRatio(bool enable)

minimumSizeHint : bool

Enable minimum size hint (will adjust size when used in layouts).

Access functions:

virtual bool minSizeHintEnabled() const
virtual void setMinSizeHint(bool enable)

pixmap : QPixmap

Use this property to add a image to the widget. Note that though ordinary svg files can be added, they should rather be added in the svgFile property as this makes them scalable without loosing quality.

Supports the following formats: .jpg , .pgn , .bmp , .gif , .tif , and more

Access functions:

virtual const QPixmap &pixmap()
virtual void setPixmap(const QPixmap &pixmap)

rotation : int

This property holds the number of degrees to rotate the picture.

The picture is rotated clockwise. Negative numbers are not supported.

Access functions:

virtual int rotation()
virtual void setRotation(int rotation)
virtual void setRotation(double rotation)

rotationVertical : bool

Access functions:

virtual bool rotationVertical()
virtual void setRotationVertical(bool enable)

scaledContents : bool

Enable this property to make the picture scalable.

Access functions:

virtual bool scaledContents() const
virtual void setScaledContents(bool enable)

svgFile : QString

This property specifies the path to the SVG file to show in the widget. The SVG does not have to be in the CDP format. Ordinary SVG files will load nicely and be scalable similar to the ones with CDP elements.

The property will also accept raster formats like .png. This property is often preferred over pixmap, as it supports themeRootDir, theme switching and shows full path in designer tools.

Access functions:

virtual QString svgFile() const
virtual void setSvgFile(const QString &svg)

See also pixmap.

Member Function Documentation

CDPBasePicture::CDPBasePicture(QWidget *parent = 0)

Default constructs an instance of CDPBasePicture.

void CDPBasePicture::addWidget(QWidget *widget, const QString &title = "")

[protected] QWidget *CDPBasePicture::canvasWidget() const

[signal] void CDPBasePicture::clicked()

[protected] QWidget *CDPBasePicture::convertToLoaderWidget(QWidget *widget) const

[protected] bool CDPBasePicture::eventFilter(QObject *watched, QEvent *event)

Implemented to update relative position when parent size is changed.

Returns base implementation with watched and event as arguments.

[virtual slot] void CDPBasePicture::forceWidgetStyle(int style)

[virtual slot] void CDPBasePicture::forceWidgetStyle(double style)

[protected slot] void CDPBasePicture::initDeprecated()

[protected] void CDPBasePicture::initPixmap(QSize pixSize)

[virtual protected] void CDPBasePicture::loadSvg()

[virtual protected] QSize CDPBasePicture::minimumSizeHint() const

[protected] void CDPBasePicture::mousePressEvent(QMouseEvent *ev)

[protected] void CDPBasePicture::mouseReleaseEvent(QMouseEvent *ev)

double CDPBasePicture::paddingAdjustedRelativePosition(double pos, bool horizontal) const

Calculates the padding-adjusted relative position for an object on the picture.

This function adjusts the given relative position pos based on the padding and content scaling properties of the picture. If the pixmap's aspect ratio is locked or the contents are not scaled, the function calculates the new position relative to the drawable area (accounting for padding). If the pixmap is null or neither of these conditions apply, it returns the original position.

Setting horizontal true, the function adjusts the horizontal position. If false, it adjusts the vertical position.

Note: This function assumes that the relative position pos is a normalized value between 0 and 1, where 0 represents the starting edge (left or top) and 1 represents the opposite edge (right or bottom).

[protected] void CDPBasePicture::paintEvent(QPaintEvent *ev)

[protected] QRect CDPBasePicture::pixmapRect() const

[protected] QSize CDPBasePicture::pixmapTargetSize(const QSize &pixSize) const

[signal] void CDPBasePicture::pressed()

[virtual protected] void CDPBasePicture::processSvgFile(QString svg)

[protected] QPoint CDPBasePicture::rectPos(const QRect &rect) const

void CDPBasePicture::removeWidgets()

[protected] void CDPBasePicture::resizeEvent(QResizeEvent *ev)

[override virtual slot] void CDPBasePicture::setCdpTargetRouting(const QString &routing)

Reimplemented from RoutingContainerBase::setCdpTargetRouting().

Sets the target routing that will be used as base for relative routing in child widget properties.

This method, exposed as a Qt slot, allows the user to configure the target routing for the container widget and propagate it to all of its child widgets. By connecting a signal to this slot, the routing can be dynamically adjusted at runtime, ensuring that all child widgets follow the specified routing pattern.

Note: Setter function for property cdpTargetRouting.

[override virtual] void CDPBasePicture::setIQtCDPPointer(IQtCDP *pIQtCDP)

[virtual slot] void CDPBasePicture::setPosX(double posX)

[virtual slot] void CDPBasePicture::setPosX(int posX)

[virtual slot] void CDPBasePicture::setPosY(double posY)

[virtual slot] void CDPBasePicture::setPosY(int posY)

[virtual slot] void CDPBasePicture::setRelativePosX(double posX)

[virtual slot] void CDPBasePicture::setRelativePosY(double posY)

[virtual slot] void CDPBasePicture::setWidgetStyle(int style)

[virtual slot] void CDPBasePicture::setWidgetTheme(const QString &theme)

QSize CDPBasePicture::sizeHint() const

The content of this document is confidential information not to be published without the consent of CDP Technologies AS.

CDP Technologies AS, www.cdpstudio.com

Get started with CDP Studio today

Let us help you take your great ideas and turn them into the products your customer will love.

Try CDP Studio for free
Why CDP Studio?

CDP Technologies AS
Hundsværgata 8,
P.O. Box 144
6001 Ålesund, Norway

Tel: +47 990 80 900
E-mail: info@cdptech.com

Company

About CDP

Contact us

Services

Partners

Blog

Developers

Get started

User manuals

Support

Document download

Release notes

My account

Follow CDP

  • LinkedIn
  • YouTube
  • GitHub

© Copyright 2025 CDP Technologies. Privacy and cookie policy.

Return to top