QWT API (中文) 7.3.0
Qt绘图库 - 中文API文档
载入中...
搜索中...
未找到
| 信号 | Public 成员函数 | 静态 Public 成员函数 | Protected 成员函数 | 所有成员列表
QwtFigure类 参考

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

#include <qwt_figure.h>

类 QwtFigure 继承关系图:

class  PrivateData
 

信号

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 成员函数

 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
 

静态 Public 成员函数

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

Protected 成员函数

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

详细描述

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

构造及析构函数说明

◆ QwtFigure()

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

Constructor

参数
parentParent widget
fWindow flags

成员函数说明

◆ 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].

参数
plotQwtPlot to add
rectNormalized coordinates [left, bottom, width, height] in range [0,1]
注解
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

参数
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]
注解
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.

参数
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.

参数
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]
注解
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.

参数
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]
注解
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.
参见
addAxes

◆ addWidget() [2/2]

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

Add a widget with normalized coordinates

参数
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]
注解
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.
参见
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.

参数
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
注解
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.

参数
byZOrderIf true, sort by z-order from top to bottom
返回
List of all QwtPlot objects (not including parasite axes)
注解
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.

参数
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.

参数
replotIf true, replot all affected plots after alignment

◆ axesAdded

void QwtFigure::axesAdded ( QwtPlot newAxes)
signal

Signal emitted when axes are added to the figure

参数
newAxesPointer to the newly added QwtPlot
注解
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.

参数
widgetWidget to query
返回
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

参数
removedAxesPointer to the removed QwtPlot
注解
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.

返回
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.

参数
indexIndex of the alignment configuration to retrieve
返回
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.

参数
normRectNormalized coordinates QRectF
返回
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.

参数
geoRectActual window coordinates (geometry)
返回
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.

注解
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.

参数
hostPlotPointer to the host QwtPlot
enableAxisThe axis position to enable on the parasite axes
返回
Pointer to the created parasite QwtPlot
返回值
nullptrif hostPlot is invalid or not in the figure
注解
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.

返回
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

参数
currentPointer to the current QwtPlot, nullptr if no valid axes
注解
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.

返回
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.

返回
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.

返回
Background brush

◆ faceColor()

QColor QwtFigure::faceColor ( ) const

Get the face color of the figure

This method returns the background color of the figure.

返回
Background color

◆ gca()

QwtPlot * QwtFigure::gca ( ) const

Get the current axes (plot)

This is a convenience method that calls currentAxes.

返回
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.

参数
hostPlotPointer to the host QwtPlot
返回
List of parasite QwtPlot pointers
返回值
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.

返回
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.

返回
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.

参数
plotQwtPlot to check
返回
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.

参数
posPosition to query
返回
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.

参数
plotQwtPlot to remove
注解
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.

参数
plotsList of plots to remove from alignment
axisIdAxis ID to remove from alignment
返回
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.

参数
filenameName of the file to save
dpiDots per inch for the saved image (-1 to use screen DPI)
返回
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.

参数
dpiDots per inch for the saved image (-1 to use screen DPI)
返回
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.

参数
inchesSizePhysical size in inches
返回
QPixmap containing the rendered figure

◆ sca()

void QwtFigure::sca ( QwtPlot plot)

Set the current axes (plot)

This is a convenience method that calls setCurrentAxes.

参数
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.

参数
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.

参数
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.

参数
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.).

参数
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.

参数
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.

参数
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.

参数
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.

参数
widget
rect

◆ takeAxes()

bool QwtFigure::takeAxes ( QwtPlot plot)

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

参数
plotPointer to the QwtPlot to take
返回
true if successfully taken, false otherwise
注解
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.

参数
widgetWidget to query
返回
Normalized coordinates [left, top, width, height] in range [0,1], or invalid QRectF if not found

该类的文档由以下文件生成: