QWT API (English) 7.3.0
Qt Widget Library for Technical Applications - English API Documentation
Loading...
Searching...
No Matches
Classes | Signals | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
QwtFigure Class Reference

A figure container for organizing Qwt plots with flexible layout options. More...

#include <qwt_figure.h>

Inheritance diagram for QwtFigure:

Classes

class  PrivateData
 

Signals

void axesAdded (QwtPlot *newAxes)
 Signal emitted when axes are added to the figure.
 
void axesRemoved (QwtPlot *removedAxes)
 Signal emitted when axes are removed from the figure.
 
void figureCleared ()
 Signal emitted when the figure is cleared.
 
void currentAxesChanged (QwtPlot *current)
 Signal emitted when the current active axes changes.
 

Public Member Functions

 QwtFigure (QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags())
 Constructor.
 
void addWidget (QWidget *widget, qreal left, qreal top, qreal width, qreal height)
 Add a widget with normalized coordinates.
 
void addWidget (QWidget *widget, int rowCnt, int colCnt, int row, int col, int rowSpan=1, int colSpan=1, qreal wspace=0.0, qreal hspace=0.0)
 Add a widget by grid layout.
 
void addAxes (QwtPlot *plot, const QRectF &rect)
 Add a plot with normalized coordinates.
 
void addAxes (QwtPlot *plot, qreal left, qreal top, qreal width, qreal height)
 Add a plot with normalized coordinates using separate parameters.
 
void addGridAxes (QwtPlot *plot, int rowCnt, int colCnt, int row, int col, int rowSpan=1, int colSpan=1, qreal wspace=0.0, qreal hspace=0.0)
 Add a plot by grid layout.
 
void setWidgetNormPos (QWidget *widget, const QRectF &rect)
 Change the normalized position of an already added widget. If the widget hasn't been added yet, this function has no effect.
 
QList< QwtPlot * > allAxes (bool byZOrder=false) const
 Get all axes (plots) in the figure (not including parasite axes)
 
bool hasAxes () const
 Check if the figure has any axes.
 
bool hasAxes (QwtPlot *plot) const
 Check if the figure contains a specific plot.
 
void removeAxes (QwtPlot *plot)
 Remove a specific axes (plot) from the figure.
 
bool takeAxes (QwtPlot *plot)
 Take a specific axes (plot) from the figure without deleting it.
 
void clear ()
 Clear all axes from the figure.
 
QSize getSizeInches () const
 Get the size of the figure in inches.
 
void setSizeInches (float width, float height)
 Set the size of the figure in inches.
 
void setSizeInches (const QSizeF &size)
 Set the size of the figure in inches.
 
void setFaceColor (const QColor &color)
 Set the face color of the figure.
 
QColor faceColor () const
 Get the face color of the figure.
 
void setFaceBrush (const QBrush &brush)
 Set the face brush of the figure.
 
QBrush faceBrush () const
 Get the face brush of the figure.
 
void setEdgeColor (const QColor &color)
 Set the edge color of the figure.
 
QColor edgeColor () const
 Get the edge color of the figure.
 
void setEdgeLineWidth (int width)
 Set the edge line width of the figure.
 
int edgeLineWidth () const
 Get the edge line width of the figure.
 
QwtPlotcreateParasiteAxes (QwtPlot *hostPlot, QwtAxis::Position enableAxis)
 Create parasite axes for a host plot.
 
QList< QwtPlot * > getParasiteAxes (QwtPlot *hostPlot) const
 Get all parasite axes for a host plot.
 
QPixmap saveFig (int dpi=-1) const
 Save the figure to a QPixmap with specified DPI.
 
QPixmap saveFig (QSizeF &inchesSize) const
 Save the figure to a QPixmap with specified size in inches.
 
bool saveFig (const QString &filename, int dpi=-1) const
 Save the figure to a file with specified DPI.
 
void setCurrentAxes (QwtPlot *plot)
 Set the current axes (plot)
 
void sca (QwtPlot *plot)
 Set the current axes (plot)
 
QwtPlotcurrentAxes () const
 Get the current axes (plot)
 
QwtPlotgca () const
 Get the current axes (plot)
 
QRectF axesNormRect (QwtPlot *plot) const
 Get the normalized rectangle for a axes.
 
QRectF widgetNormRect (QWidget *w) const
 Get the normalized rectangle for a widget.
 
QwtPlotplotUnderPos (const QPoint &pos) const
 Get the plot under a position.
 
QRectF calcNormRect (const QRect &geoRect) const
 Calculate normalized coordinates from actual window coordinates.
 
QRect calcActualRect (const QRectF &normRect)
 Calculate actual rectangle from normalized coordinates.
 
void replotAll ()
 Update all plots in the figure.
 
void addAxisAlignment (const QList< QwtPlot * > &plots, int axisId)
 Add axis alignment configuration.
 
bool removeAxisAlignment (const QList< QwtPlot * > &plots, int axisId)
 Remove specified axis alignment configuration.
 
void clearAxisAlignment ()
 Clear all axis alignment configurations.
 
void applyAllAxisAlignments (bool replot=true)
 Apply all axis alignment configurations.
 
void applyAlignmentsForAxis (int axisId)
 Apply alignment configurations for a specific axis.
 
int axisAligmentCount () const
 Get the number of axis alignment configurations.
 
QPair< QList< QwtPlot * >, int > axisAligmentInfo (int index) const
 Get axis alignment information by index.
 

Static Public Member Functions

static void alignAxes (QList< QwtPlot * > plots, int axisId, bool update=true)
 Align axes of multiple plots.
 

Protected Member Functions

void paintEvent (QPaintEvent *event) override
 
void resizeEvent (QResizeEvent *event) override
 

Detailed Description

A figure container for organizing Qwt plots with flexible layout options.

This class provides a figure-like container similar to matplotlib's Figure class, supporting both normalized coordinate positioning and grid layouts for Qwt plots. It uses Qt's standard top-left coordinate system for intuitive positioning.

Example:
// Example usage:
QwtFigure figure;
// Add a plot using normalized coordinates (Qt top-left coordinate system)
QwtPlot* plot1 = new QwtPlot;
figure.addAxes(plot1, QRectF(0.1, 0.1, 0.8, 0.4));
// Add plots using grid layout - Create a 2x2 grid
QwtPlot* plot2 = new QwtPlot;
figure.addAxes(plot2, 2, 2, 0, 1); // 2x2 grid, row 0, column 1
QwtPlot* plot3 = new QwtPlot;
figure.addAxes(plot3, 2, 2, 1, 0, 1, 2); // row 1, columns 0-1 (span 2 columns)
// Save the figure
figure.saveFig("output.png", 300);
A figure container for organizing Qwt plots with flexible layout options.
Definition qwt_figure.h:47
QPixmap saveFig(int dpi=-1) const
Save the figure to a QPixmap with specified DPI.
Definition qwt_figure.cpp:602
void addAxes(QwtPlot *plot, const QRectF &rect)
Add a plot with normalized coordinates.
Definition qwt_figure.cpp:151
A 2-D plotting widget.
Definition qwt_plot.h:99

Constructor & Destructor Documentation

◆ QwtFigure()

QwtFigure::QwtFigure ( QWidget *  parent = nullptr,
Qt::WindowFlags  f = Qt::WindowFlags() 
)

Constructor.

Parameters
parentParent widget
fWindow flags

Member Function Documentation

◆ addAxes() [1/2]

void QwtFigure::addAxes ( QwtPlot plot,
const QRectF &  rect 
)

Add a plot with normalized coordinates.

This method adds a QwtPlot to the figure using normalized coordinates in the range [0,1]. The coordinates are specified as [left, bottom, width, height].

Parameters
plotQwtPlot to add
rectNormalized coordinates [left, bottom, width, height] in range [0,1]
Note
This function will emit axesAdded signal, followed by currentAxesChanged signal

◆ addAxes() [2/2]

void QwtFigure::addAxes ( QwtPlot plot,
qreal  left,
qreal  top,
qreal  width,
qreal  height 
)

Add a plot with normalized coordinates using separate parameters.

Parameters
plotQwtPlot to add
leftNormalized coordinates left in range [0,1]
topNormalized coordinates top in range [0,1]
widthNormalized coordinates width in range [0,1]
heightNormalized coordinates height in range [0,1]
Note
This function will emit axesAdded signal, followed by currentAxesChanged signal

◆ addAxisAlignment()

void QwtFigure::addAxisAlignment ( const QList< QwtPlot * > &  plots,
int  axisId 
)

Add axis alignment configuration.

This method adds an alignment configuration for the specified plots and axis.

Parameters
plotsList of plots to align
axisIdAxis ID to align (QwtAxis::XTop/XBottom/YLeft/YRight)

◆ addGridAxes()

void QwtFigure::addGridAxes ( QwtPlot plot,
int  rowCnt,
int  colCnt,
int  row,
int  col,
int  rowSpan = 1,
int  colSpan = 1,
qreal  wspace = 0.0,
qreal  hspace = 0.0 
)

Add a plot by grid layout.

This method adds a QwtPlot to the grid layout at the specified position with optional row and column spans.

Parameters
plotQwtPlot to add
rowCntNumber of rows in the grid
colCntNumber of columns in the grid
rowGrid row position (0-based)
colGrid column position (0-based)
rowSpanNumber of rows to span (default: 1)
colSpanNumber of columns to span (default: 1)
wspaceHorizontal space between subplots [0,1]
hspaceVertical space between subplots [0,1]
Note
This function will emit axesAdded signal, followed by currentAxesChanged signal

◆ addWidget() [1/2]

void QwtFigure::addWidget ( QWidget *  widget,
int  rowCnt,
int  colCnt,
int  row,
int  col,
int  rowSpan = 1,
int  colSpan = 1,
qreal  wspace = 0.0,
qreal  hspace = 0.0 
)

Add a widget by grid layout.

This method adds a widget to the grid layout at the specified position with optional row and column spans.

Parameters
widgetWidget to add
rowCntNumber of rows in the grid
colCntNumber of columns in the grid
rowGrid row position (0-based)
colGrid column position (0-based)
rowSpanNumber of rows to span (default: 1)
colSpanNumber of columns to span (default: 1)
wspaceHorizontal space between subplots [0,1]
hspaceVertical space between subplots [0,1]
Note
Even if the added widget is a QwtPlot, this function will not emit axesAdded signal. Use addAxes() instead if you need to add QwtPlot widgets.
See also
addAxes

◆ addWidget() [2/2]

void QwtFigure::addWidget ( QWidget *  widget,
qreal  left,
qreal  top,
qreal  width,
qreal  height 
)

Add a widget with normalized coordinates.

Parameters
widgetQWidget to add
leftNormalized coordinates left in range [0,1]
topNormalized coordinates top in range [0,1]
widthNormalized coordinates width in range [0,1]
heightNormalized coordinates height in range [0,1]
Note
Even if the added widget is a QwtPlot, this function will not emit axesAdded signal. Use addAxes() instead if you need to add QwtPlot widgets.
See also
addAxes

◆ alignAxes()

void QwtFigure::alignAxes ( QList< QwtPlot * >  plots,
int  axisId,
bool  update = true 
)
static

Align axes of multiple plots.

This function unifies the minimumExtent and minBorderDist of the specified axis to ensure visual alignment of axes.

Parameters
plotsList of QwtPlot to align (must be non-empty)
axisIdAxis ID to align (QwtAxis::XTop/XBottom/YLeft/YRight)
replotIf true, update layout and replot after alignment
Note
This function should be called after widget initialization (e.g., in showEvent/resizeEvent).
Supports any number of plots and any valid axis type, adapting to horizontal/vertical layouts.
Do not pass parasite axes, currently only supports host axes.

◆ allAxes()

QList< QwtPlot * > QwtFigure::allAxes ( bool  byZOrder = false) const

Get all axes (plots) in the figure (not including parasite axes)

This method returns a list of all QwtPlot objects added to the figure.

Parameters
byZOrderIf true, sort by z-order from top to bottom
Returns
List of all QwtPlot objects (not including parasite axes)
Note
Parasite axes are not included in the returned list

◆ applyAlignmentsForAxis()

void QwtFigure::applyAlignmentsForAxis ( int  axisId)

Apply alignment configurations for a specific axis.

This method applies all alignment configurations for the specified axis ID.

Parameters
axisIdAxis ID to apply alignments for

◆ applyAllAxisAlignments()

void QwtFigure::applyAllAxisAlignments ( bool  replot = true)

Apply all axis alignment configurations.

This method applies all recorded alignment configurations to the plots.

Parameters
replotIf true, replot all affected plots after alignment

◆ axesAdded

void QwtFigure::axesAdded ( QwtPlot newAxes)
signal

Signal emitted when axes are added to the figure.

Parameters
newAxesPointer to the newly added QwtPlot
Note
Parasite axes addition also triggers this signal

◆ axesNormRect()

QRectF QwtFigure::axesNormRect ( QwtPlot plot) const

Get the normalized rectangle for a axes.

This method returns the normalized coordinates [0,1] for the specified axes in the figure. If the axes is not found in the figure, an invalid QRectF is returned.

Parameters
widgetWidget to query
Returns
Normalized coordinates [left, top, width, height] in range [0,1], or invalid QRectF if not found

◆ axesRemoved

void QwtFigure::axesRemoved ( QwtPlot removedAxes)
signal

Signal emitted when axes are removed from the figure.

Parameters
removedAxesPointer to the removed QwtPlot
Note
Parasite axes removal also triggers this signal

◆ axisAligmentCount()

int QwtFigure::axisAligmentCount ( ) const

Get the number of axis alignment configurations.

This method returns the count of alignment configurations added via addAxisAlignment.

Returns
Number of alignment configurations

◆ axisAligmentInfo()

QPair< QList< QwtPlot * >, int > QwtFigure::axisAligmentInfo ( int  index) const

Get axis alignment information by index.

This method returns the alignment configuration at the specified index.

Parameters
indexIndex of the alignment configuration to retrieve
Returns
QPair containing the plot list and axis ID

◆ calcActualRect()

QRect QwtFigure::calcActualRect ( const QRectF &  normRect)

Calculate actual rectangle from normalized coordinates.

This method converts normalized coordinates to actual window coordinates.

Parameters
normRectNormalized coordinates QRectF
Returns
Actual window coordinates QRect

◆ calcNormRect()

QRectF QwtFigure::calcNormRect ( const QRect &  geoRect) const

Calculate normalized coordinates from actual window coordinates.

This method converts actual window coordinates (geometry) to normalized coordinates.

Parameters
geoRectActual window coordinates (geometry)
Returns
Normalized coordinates QRectF

◆ clear()

void QwtFigure::clear ( )

Clear all axes from the figure.

This method removes all QwtPlot objects from the figure and deletes them.

Note
This method emits axesRemoved signal during removal process.
After all removals, currentAxesChanged signal is emitted with nullptr, then figureCleared signal.
This method deletes all held plot widgets.

◆ clearAxisAlignment()

void QwtFigure::clearAxisAlignment ( )

Clear all axis alignment configurations.

This method removes all alignment configurations from the figure.

◆ createParasiteAxes()

QwtPlot * QwtFigure::createParasiteAxes ( QwtPlot hostPlot,
QwtAxis::Position  enableAxis 
)

Create parasite axes for a host plot.

This method creates a parasite axes that shares the same plotting area as the host plot but with independent axis scaling and labeling. The parasite axes will be positioned exactly on top of the host plot and will automatically synchronize its geometry.

Parameters
hostPlotPointer to the host QwtPlot
enableAxisThe axis position to enable on the parasite axes
Returns
Pointer to the created parasite QwtPlot
Return values
nullptrif hostPlot is invalid or not in the figure
Note
The parasite axes will have a transparent background and only the specified axis will be visible.
The parasite axes will automatically be deleted when the host plot is removed from the figure.
Parasitic axes are not stored in QwtFigureLayout, but are separately controlled by QwtFigure for layout management.
Parasite axes must be managed by the figure because they only overlap the plotting area with the host, while the coordinate window positions are different from the host.

◆ currentAxes()

QwtPlot * QwtFigure::currentAxes ( ) const

Get the current axes (plot)

This method returns the current active QwtPlot in the figure. The current axes is typically the last axes that was added, modified, or plotted on.

Returns
Pointer to the current QwtPlot, or nullptr if no axes exist

◆ currentAxesChanged

void QwtFigure::currentAxesChanged ( QwtPlot current)
signal

Signal emitted when the current active axes changes.

Parameters
currentPointer to the current QwtPlot, nullptr if no valid axes
Note
Parasite axes cannot be set as current axes

◆ edgeColor()

QColor QwtFigure::edgeColor ( ) const

Get the edge color of the figure.

This method returns the border color of the figure.

Returns
Border color

◆ edgeLineWidth()

int QwtFigure::edgeLineWidth ( ) const

Get the edge line width of the figure.

This method returns the border line width of the figure.

Returns
Border line width in pixels

◆ faceBrush()

QBrush QwtFigure::faceBrush ( ) const

Get the face brush of the figure.

This method returns the background brush of the figure.

Returns
Background brush

◆ faceColor()

QColor QwtFigure::faceColor ( ) const

Get the face color of the figure.

This method returns the background color of the figure.

Returns
Background color

◆ gca()

QwtPlot * QwtFigure::gca ( ) const

Get the current axes (plot)

This is a convenience method that calls currentAxes.

Returns
Pointer to the current QwtPlot, or nullptr if no axes exist

◆ getParasiteAxes()

QList< QwtPlot * > QwtFigure::getParasiteAxes ( QwtPlot hostPlot) const

Get all parasite axes for a host plot.

This method returns a list of all parasite axes associated with the specified host plot.

Parameters
hostPlotPointer to the host QwtPlot
Returns
List of parasite QwtPlot pointers
Return values
Emptylist if hostPlot is invalid or has no parasite axes

◆ getSizeInches()

QSize QwtFigure::getSizeInches ( ) const

Get the size of the figure in inches.

This method calculates the physical size of the figure in inches based on the current pixel size and screen DPI.

Returns
Size of the figure in inches

◆ hasAxes() [1/2]

bool QwtFigure::hasAxes ( ) const

Check if the figure has any axes.

This method returns true if the figure contains at least one QwtPlot.

Returns
true if the figure has axes, false otherwise

◆ hasAxes() [2/2]

bool QwtFigure::hasAxes ( QwtPlot plot) const

Check if the figure contains a specific plot.

This method returns true if the figure contains the specified QwtPlot.

Parameters
plotQwtPlot to check
Returns
true if the figure contains the plot, false otherwise

◆ plotUnderPos()

QwtPlot * QwtFigure::plotUnderPos ( const QPoint &  pos) const

Get the plot under a position.

This method returns the QwtPlot under the specified position. If no plot is found, nullptr is returned. Hidden windows are not considered.

Parameters
posPosition to query
Returns
Pointer to the QwtPlot under the position, or nullptr if not found

◆ removeAxes()

void QwtFigure::removeAxes ( QwtPlot plot)

Remove a specific axes (plot) from the figure.

This method removes the specified QwtPlot from the figure.

Parameters
plotQwtPlot to remove
Note
This function does not destroy the QwtPlot object. You need to call deleteLater() manually.

◆ removeAxisAlignment()

bool QwtFigure::removeAxisAlignment ( const QList< QwtPlot * > &  plots,
int  axisId 
)

Remove specified axis alignment configuration.

This method removes the alignment configuration for the specified plots and axis.

Parameters
plotsList of plots to remove from alignment
axisIdAxis ID to remove from alignment
Returns
true if successfully removed, false otherwise

◆ replotAll()

void QwtFigure::replotAll ( )

Update all plots in the figure.

This method calls replot on all plots in the figure.

◆ saveFig() [1/3]

bool QwtFigure::saveFig ( const QString &  filename,
int  dpi = -1 
) const

Save the figure to a file with specified DPI.

This method saves the figure to an image file with the specified DPI.

Parameters
filenameName of the file to save
dpiDots per inch for the saved image (-1 to use screen DPI)
Returns
true if saved successfully, false otherwise

◆ saveFig() [2/3]

QPixmap QwtFigure::saveFig ( int  dpi = -1) const

Save the figure to a QPixmap with specified DPI.

This method renders the figure to a QPixmap with the specified DPI. If DPI is -1, the current screen DPI is used.

Parameters
dpiDots per inch for the saved image (-1 to use screen DPI)
Returns
QPixmap containing the rendered figure

◆ saveFig() [3/3]

QPixmap QwtFigure::saveFig ( QSizeF &  inchesSize) const

Save the figure to a QPixmap with specified size in inches.

This method renders the figure to a QPixmap with the specified physical size in inches. The current DPI setting of the figure is used to calculate the pixel size.

Parameters
inchesSizePhysical size in inches
Returns
QPixmap containing the rendered figure

◆ sca()

void QwtFigure::sca ( QwtPlot plot)

Set the current axes (plot)

This is a convenience method that calls setCurrentAxes.

Parameters
plotQwtPlot to set as current

◆ setCurrentAxes()

void QwtFigure::setCurrentAxes ( QwtPlot plot)

Set the current axes (plot)

This method sets the specified QwtPlot as the current active axes in the figure.

Parameters
plotQwtPlot to set as current

◆ setEdgeColor()

void QwtFigure::setEdgeColor ( const QColor &  color)

Set the edge color of the figure.

This method sets the border color of the figure.

Parameters
colorBorder color

◆ setEdgeLineWidth()

void QwtFigure::setEdgeLineWidth ( int  width)

Set the edge line width of the figure.

This method sets the border line width of the figure.

Parameters
widthBorder line width in pixels

◆ setFaceBrush()

void QwtFigure::setFaceBrush ( const QBrush &  brush)

Set the face brush of the figure.

This method sets the background brush of the figure, allowing for more complex backgrounds (gradients, textures, etc.).

Parameters
brushBackground brush

◆ setFaceColor()

void QwtFigure::setFaceColor ( const QColor &  color)

Set the face color of the figure.

This method sets the background color of the figure.

Parameters
colorBackground color

◆ setSizeInches() [1/2]

void QwtFigure::setSizeInches ( const QSizeF &  size)

Set the size of the figure in inches.

This method sets the size of the figure in inches, converting to pixels based on the screen DPI.

Parameters
sizeSize in inches

◆ setSizeInches() [2/2]

void QwtFigure::setSizeInches ( float  width,
float  height 
)

Set the size of the figure in inches.

This method sets the size of the figure in inches, converting to pixels based on the screen DPI.

Parameters
widthWidth in inches
heightHeight in inches

◆ setWidgetNormPos()

void QwtFigure::setWidgetNormPos ( QWidget *  widget,
const QRectF &  rect 
)

Change the normalized position of an already added widget. If the widget hasn't been added yet, this function has no effect.

Parameters
widget
rect

◆ takeAxes()

bool QwtFigure::takeAxes ( QwtPlot plot)

Take a specific axes (plot) from the figure without deleting it.

Parameters
plotPointer to the QwtPlot to take
Returns
true if successfully taken, false otherwise
Note
If the removed plot is the current active axes, currentAxesChanged signal is emitted first, then axesRemoved signal.
If the figure has no plots after removal, currentAxesChanged signal is emitted with nullptr.
If a plot has parasite axes, they will be hidden and have parent widget set to nullptr.

◆ widgetNormRect()

QRectF QwtFigure::widgetNormRect ( QWidget *  w) const

Get the normalized rectangle for a widget.

This method returns the normalized coordinates [0,1] for the specified axes in the figure. If the widget is not found in the figure, an invalid QRectF is returned.

Parameters
widgetWidget to query
Returns
Normalized coordinates [left, top, width, height] in range [0,1], or invalid QRectF if not found

The documentation for this class was generated from the following files: