Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
QmitkPlotWidget Class Reference

Convenience widget providing a high-level interface for plotting curves using Qwt. More...

#include <QmitkPlotWidget.h>

Inheritance diagram for QmitkPlotWidget:
Collaboration diagram for QmitkPlotWidget:

Public Types

typedef double ScalarType
 Scalar type used for data values (double, defined by Qwt). More...
 
typedef std::vector< ScalarType > DataVector
 Vector of scalar values representing x or y coordinates. More...
 
typedef std::vector< std::pair< double, double > > XYDataVector
 Vector of (x, y) pairs representing curve data points. More...
 

Public Member Functions

 QmitkPlotWidget (QWidget *parent=nullptr, const char *title=nullptr, const char *name=nullptr, Qt::WindowFlags f={})
 Construct the plot widget. More...
 
 ~QmitkPlotWidget () override
 Destructor. Clears all curves and deletes the plot. More...
 
QwtPlot * GetPlot ()
 Get the underlying QwtPlot instance for low-level customization. More...
 
void SetPlotTitle (const QwtText &qwt_title)
 Set the plot title using a formatted QwtText. More...
 
void SetPlotTitle (const char *title)
 Set the plot title using plain text. More...
 
unsigned int InsertCurve (const char *title, QColor color=QColor(Qt::black))
 Insert a new curve into the plot. More...
 
void SetAxisTitle (int axis, const char *title)
 Set the title of an axis. More...
 
bool SetCurveData (unsigned int curveId, const DataVector &xValues, const DataVector &yValues)
 Set curve data from separate x and y vectors. More...
 
bool SetCurveData (unsigned int curveId, const DataVector &xValues, const DataVector &yValues, const DataVector &yLowerError, const DataVector &yUpperError)
 Set curve data with y-axis error bars. More...
 
bool SetCurveData (unsigned int curveId, const DataVector &xValues, const DataVector &yValues, const DataVector &xLowerError, const DataVector &xUpperError, const DataVector &yLowerError, const DataVector &yUpperError)
 Set curve data with both x and y error bars. More...
 
bool SetCurveData (unsigned int curveId, const XYDataVector &data)
 Set curve data from a vector of (x, y) pairs. More...
 
void SetCurvePen (unsigned int curveId, const QPen &pen)
 Set the pen (line style) for a curve. More...
 
void SetCurveBrush (unsigned int curveId, const QBrush &brush)
 Set the brush (fill pattern) for a curve. More...
 
void SetCurveStyle (unsigned int curveId, const QwtPlotCurve::CurveStyle style)
 Set the curve drawing style (lines, sticks, dots, etc.). More...
 
void SetCurveSymbol (unsigned int curveId, QwtSymbol *symbol)
 Set the symbol used for drawing data points. More...
 
void SetCurveAntialiasingOn (unsigned int curveId)
 Enable antialiasing for a curve. More...
 
void SetCurveAntialiasingOff (unsigned int curveId)
 Disable antialiasing for a curve. More...
 
void SetCurveTitle (unsigned int curveId, const char *title)
 Set the title of a curve (shown in the plot title, not legend). More...
 
void SetErrorPen (unsigned int curveId, const QPen &pen)
 Set the pen for drawing error bars. More...
 
void SetErrorStyleSymbols (unsigned int curveId, bool drawSmybols)
 Set error bar drawing style. More...
 
void SetLegend (QwtLegend *legend, QwtPlot::LegendPosition pos=QwtPlot::RightLegend, double ratio=-1)
 Set the plot legend. More...
 
void SetLegendAttribute (unsigned int curveId, const QwtPlotCurve::LegendAttribute &attribute)
 Set a legend attribute for a curve. More...
 
void Replot ()
 Trigger a replot. Call after setting new data or changing appearance. More...
 
void Clear ()
 Clear all curves and reset the plot to an empty state. More...
 

Protected Member Functions

double * ConvertToRawArray (const DataVector &values)
 
double * ConvertToRawArray (const XYDataVector &values, unsigned int component)
 
bool AddErrorIntervalCurve (unsigned int curveId, const DataVector &lessError, const DataVector &moreError, bool isXError)
 

Protected Attributes

QwtPlot * m_Plot
 
std::vector< std::tuple< QwtPlotCurve *, QwtPlotIntervalCurve *, QwtPlotIntervalCurve * > > m_PlotCurveVector
 

Detailed Description

Convenience widget providing a high-level interface for plotting curves using Qwt.

Wraps a QwtPlot and provides methods for inserting curves, setting data, configuring appearance (pen, brush, symbols), and managing error bars. Can be used standalone or inside a QmitkPlotDialog.

Usage example:

QmitkPlotWidget* widget = new QmitkPlotWidget(this, "widget");
widget->SetAxisTitle(QwtPlot::xBottom, "X [mm]");
widget->SetAxisTitle(QwtPlot::yLeft, "Y [mm]");
int curveId = widget->InsertCurve("My data");
widget->SetCurveData(curveId, xValues, yValues);
widget->SetCurvePen(curveId, QPen(Qt::red));
widget->Replot();
Convenience widget providing a high-level interface for plotting curves using Qwt.
bool SetCurveData(unsigned int curveId, const DataVector &xValues, const DataVector &yValues)
Set curve data from separate x and y vectors.
void SetCurvePen(unsigned int curveId, const QPen &pen)
Set the pen (line style) for a curve.
unsigned int InsertCurve(const char *title, QColor color=QColor(Qt::black))
Insert a new curve into the plot.
void SetAxisTitle(int axis, const char *title)
Set the title of an axis.
void Replot()
Trigger a replot. Call after setting new data or changing appearance.
QmitkPlotWidget(QWidget *parent=nullptr, const char *title=nullptr, const char *name=nullptr, Qt::WindowFlags f={})
Construct the plot widget.
Note
QmitkChartWidget is the preferred alternative for new code.
See also
QmitkPlotDialog, QwtPlot, QmitkChartWidget

Definition at line 50 of file QmitkPlotWidget.h.

Member Typedef Documentation

◆ DataVector

Vector of scalar values representing x or y coordinates.

Definition at line 61 of file QmitkPlotWidget.h.

◆ ScalarType

Scalar type used for data values (double, defined by Qwt).

Definition at line 58 of file QmitkPlotWidget.h.

◆ XYDataVector

typedef std::vector<std::pair<double, double> > QmitkPlotWidget::XYDataVector

Vector of (x, y) pairs representing curve data points.

Definition at line 64 of file QmitkPlotWidget.h.

Constructor & Destructor Documentation

◆ QmitkPlotWidget()

QmitkPlotWidget::QmitkPlotWidget ( QWidget *  parent = nullptr,
const char *  title = nullptr,
const char *  name = nullptr,
Qt::WindowFlags  f = {} 
)

Construct the plot widget.

Parameters
[in]parentThe parent widget.
[in]titleThe plot title.
[in]nameThe object name (unused, kept for compatibility).
[in]fWindow flags.

◆ ~QmitkPlotWidget()

QmitkPlotWidget::~QmitkPlotWidget ( )
override

Destructor. Clears all curves and deletes the plot.

Member Function Documentation

◆ AddErrorIntervalCurve()

bool QmitkPlotWidget::AddErrorIntervalCurve ( unsigned int  curveId,
const DataVector &  lessError,
const DataVector &  moreError,
bool  isXError 
)
protected

Adds an error interval curve.

All errors should be absolutes. The magnitude will be used.

Parameters
curveIdWhich curve should the error curve be added to
lessErrorError in the negative direction (value - lessError)
moreErrorError in the positive direction (value + lessError)
isXErrorShould the error bars be drawn horizontally

◆ Clear()

void QmitkPlotWidget::Clear ( )

Clear all curves and reset the plot to an empty state.

◆ ConvertToRawArray() [1/2]

double* QmitkPlotWidget::ConvertToRawArray ( const DataVector &  values)
protected

Converts the given values into a raw double* array. A new array is allocated via new and must be deleted[] by the caller.

◆ ConvertToRawArray() [2/2]

double* QmitkPlotWidget::ConvertToRawArray ( const XYDataVector &  values,
unsigned int  component 
)
protected

Converts the given values into a raw double* array. A new array is allocated via new and must be deleted[] by the caller.

Parameters
valuesthe x/y values to convert to an array
componentdefines if the x values (0) or the y values(1) should be converted. Other values than 0 and 1 will not be accepted.

◆ GetPlot()

QwtPlot* QmitkPlotWidget::GetPlot ( )

Get the underlying QwtPlot instance for low-level customization.

Returns
Pointer to the QwtPlot.

◆ InsertCurve()

unsigned int QmitkPlotWidget::InsertCurve ( const char *  title,
QColor  color = QColor(Qt::black) 
)

Insert a new curve into the plot.

Parameters
[in]titleThe curve name (shown in legend).
[in]colorThe curve title text color (default black).
Returns
The curve ID used to reference this curve in subsequent calls.

◆ Replot()

void QmitkPlotWidget::Replot ( )

Trigger a replot. Call after setting new data or changing appearance.

◆ SetAxisTitle()

void QmitkPlotWidget::SetAxisTitle ( int  axis,
const char *  title 
)

Set the title of an axis.

Parameters
[in]axisThe axis identifier (e.g. QwtPlot::xBottom, QwtPlot::yLeft).
[in]titleThe axis title.

◆ SetCurveAntialiasingOff()

void QmitkPlotWidget::SetCurveAntialiasingOff ( unsigned int  curveId)

Disable antialiasing for a curve.

Parameters
[in]curveIdThe curve ID.

◆ SetCurveAntialiasingOn()

void QmitkPlotWidget::SetCurveAntialiasingOn ( unsigned int  curveId)

Enable antialiasing for a curve.

Parameters
[in]curveIdThe curve ID.

◆ SetCurveBrush()

void QmitkPlotWidget::SetCurveBrush ( unsigned int  curveId,
const QBrush &  brush 
)

Set the brush (fill pattern) for a curve.

When set, the area between the curve and the baseline is filled. Curve data should be sorted for correct filling.

Parameters
[in]curveIdThe curve ID.
[in]brushThe QBrush defining the fill pattern.

◆ SetCurveData() [1/4]

bool QmitkPlotWidget::SetCurveData ( unsigned int  curveId,
const DataVector &  xValues,
const DataVector &  yValues 
)

Set curve data from separate x and y vectors.

Parameters
[in]curveIdThe curve ID.
[in]xValuesThe x coordinates.
[in]yValuesThe y coordinates.
Precondition
xValues and yValues must have the same size.
Returns
True if data was set successfully.

◆ SetCurveData() [2/4]

bool QmitkPlotWidget::SetCurveData ( unsigned int  curveId,
const DataVector &  xValues,
const DataVector &  yValues,
const DataVector &  xLowerError,
const DataVector &  xUpperError,
const DataVector &  yLowerError,
const DataVector &  yUpperError 
)

Set curve data with both x and y error bars.

Parameters
[in]curveIdThe curve ID.
[in]xValuesThe x coordinates.
[in]yValuesThe y coordinates.
[in]xLowerErrorThe magnitude of the error in the negative x direction.
[in]xUpperErrorThe magnitude of the error in the positive x direction.
[in]yLowerErrorThe magnitude of the error in the negative y direction.
[in]yUpperErrorThe magnitude of the error in the positive y direction.
Returns
True if data was set successfully.

◆ SetCurveData() [3/4]

bool QmitkPlotWidget::SetCurveData ( unsigned int  curveId,
const DataVector &  xValues,
const DataVector &  yValues,
const DataVector &  yLowerError,
const DataVector &  yUpperError 
)

Set curve data with y-axis error bars.

Parameters
[in]curveIdThe curve ID.
[in]xValuesThe x coordinates.
[in]yValuesThe y coordinates.
[in]yLowerErrorThe magnitude of the error in the negative y direction.
[in]yUpperErrorThe magnitude of the error in the positive y direction.
Returns
True if data was set successfully.

◆ SetCurveData() [4/4]

bool QmitkPlotWidget::SetCurveData ( unsigned int  curveId,
const XYDataVector &  data 
)

Set curve data from a vector of (x, y) pairs.

Parameters
[in]curveIdThe curve ID.
[in]dataThe vector of coordinate pairs.
Returns
True if data was set successfully.

◆ SetCurvePen()

void QmitkPlotWidget::SetCurvePen ( unsigned int  curveId,
const QPen &  pen 
)

Set the pen (line style) for a curve.

Parameters
[in]curveIdThe curve ID.
[in]penThe QPen defining line color, width, and style.

◆ SetCurveStyle()

void QmitkPlotWidget::SetCurveStyle ( unsigned int  curveId,
const QwtPlotCurve::CurveStyle  style 
)

Set the curve drawing style (lines, sticks, dots, etc.).

Parameters
[in]curveIdThe curve ID.
[in]styleThe QwtPlotCurve::CurveStyle.

◆ SetCurveSymbol()

void QmitkPlotWidget::SetCurveSymbol ( unsigned int  curveId,
QwtSymbol *  symbol 
)

Set the symbol used for drawing data points.

Parameters
[in]curveIdThe curve ID.
[in]symbolThe QwtSymbol (ownership transferred to the curve).

◆ SetCurveTitle()

void QmitkPlotWidget::SetCurveTitle ( unsigned int  curveId,
const char *  title 
)

Set the title of a curve (shown in the plot title, not legend).

Parameters
[in]curveIdThe curve ID.
[in]titleThe curve title.

◆ SetErrorPen()

void QmitkPlotWidget::SetErrorPen ( unsigned int  curveId,
const QPen &  pen 
)

Set the pen for drawing error bars.

Parameters
[in]curveIdThe curve ID.
[in]penThe QPen for error bars.

◆ SetErrorStyleSymbols()

void QmitkPlotWidget::SetErrorStyleSymbols ( unsigned int  curveId,
bool  drawSmybols 
)

Set error bar drawing style.

Parameters
[in]curveIdThe curve ID.
[in]drawSmybolsTrue to draw error bars as symbols, false as a filled tube.

◆ SetLegend()

void QmitkPlotWidget::SetLegend ( QwtLegend *  legend,
QwtPlot::LegendPosition  pos = QwtPlot::RightLegend,
double  ratio = -1 
)

Set the plot legend.

Parameters
[in]legendThe QwtLegend widget.
[in]posThe legend position (default: right).
[in]ratioThe legend size ratio (-1 for automatic).

◆ SetLegendAttribute()

void QmitkPlotWidget::SetLegendAttribute ( unsigned int  curveId,
const QwtPlotCurve::LegendAttribute &  attribute 
)

Set a legend attribute for a curve.

Parameters
[in]curveIdThe curve ID.
[in]attributeThe legend attribute to set.

◆ SetPlotTitle() [1/2]

void QmitkPlotWidget::SetPlotTitle ( const char *  title)

Set the plot title using plain text.

Parameters
[in]titleThe title string.

◆ SetPlotTitle() [2/2]

void QmitkPlotWidget::SetPlotTitle ( const QwtText &  qwt_title)

Set the plot title using a formatted QwtText.

Parameters
[in]qwt_titleThe formatted title.

Member Data Documentation

◆ m_Plot

QwtPlot* QmitkPlotWidget::m_Plot
protected

Definition at line 283 of file QmitkPlotWidget.h.

◆ m_PlotCurveVector

std::vector<std::tuple<QwtPlotCurve *, QwtPlotIntervalCurve *, QwtPlotIntervalCurve *> > QmitkPlotWidget::m_PlotCurveVector
protected

Definition at line 284 of file QmitkPlotWidget.h.


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