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

A class which draws a legend inside the plot canvas. More...

#include <qwt_plot_legenditem.h>

Inheritance diagram for QwtPlotLegendItem:
QwtPlotItem

Classes

class  PrivateData
 

Public Types

enum  BackgroundMode { LegendBackground , ItemBackground }
 Background mode. More...
 
- Public Types inherited from QwtPlotItem
enum  RttiValues {
  Rtti_PlotItem = 0 , Rtti_PlotGrid , Rtti_PlotScale , Rtti_PlotLegend ,
  Rtti_PlotMarker , Rtti_PlotCurve , Rtti_PlotSpectroCurve , Rtti_PlotIntervalCurve ,
  Rtti_PlotHistogram , Rtti_PlotSpectrogram , Rtti_PlotGraphic , Rtti_PlotTradingCurve ,
  Rtti_PlotBarChart , Rtti_PlotMultiBarChart , Rtti_PlotShape , Rtti_PlotTextLabel ,
  Rtti_PlotZone , Rtti_PlotVectorField , Rtti_PlotArrowMarker , Rtti_PlotBoxChart ,
  Rtti_PlotUserItem = 1000
}
 Runtime type information. More...
 
enum  ItemAttribute { Legend = 0x01 , AutoScale = 0x02 , Margins = 0x04 }
 Plot Item Attributes. More...
 
enum  ItemInterest { ScaleInterest = 0x01 , LegendInterest = 0x02 }
 Plot Item Interests. More...
 
enum  RenderHint { RenderAntialiased = 0x1 }
 Render hints. More...
 

Public Member Functions

 QwtPlotLegendItem ()
 Constructor.
 
 ~QwtPlotLegendItem () override
 Destructor.
 
virtual int rtti () const override
 Get the runtime type information.
 
void setAlignmentInCanvas (Qt::Alignment)
 Set the alignment in canvas.
 
Qt::Alignment alignmentInCanvas () const
 Get the alignment in canvas.
 
void setOffsetInCanvas (Qt::Orientations, int numPixels)
 Set the offset in canvas.
 
int offsetInCanvas (Qt::Orientation) const
 Get the offset in canvas.
 
void setMaxColumns (uint)
 Set the maximum number of columns.
 
uint maxColumns () const
 Get the maximum number of columns.
 
void setMargin (int)
 Set the margin.
 
int margin () const
 Get the margin.
 
void setSpacing (int)
 Set the spacing.
 
int spacing () const
 Get the spacing.
 
void setItemMargin (int)
 Set the item margin.
 
int itemMargin () const
 Get the item margin.
 
void setItemSpacing (int)
 Set the item spacing.
 
int itemSpacing () const
 Get the item spacing.
 
void setFont (const QFont &)
 Set the font.
 
QFont font () const
 Get the font.
 
void setBorderRadius (double)
 Set the border radius.
 
double borderRadius () const
 Get the border radius.
 
void setBorderPen (const QPen &)
 Set the border pen.
 
QPen borderPen () const
 Get the border pen.
 
void setBackgroundBrush (const QBrush &)
 Set the background brush.
 
QBrush backgroundBrush () const
 Get the background brush.
 
void setBackgroundMode (BackgroundMode)
 Set the background mode.
 
BackgroundMode backgroundMode () const
 Get the background mode.
 
void setTextPen (const QPen &)
 Set the text pen.
 
QPen textPen () const
 Get the text pen.
 
virtual void draw (QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect) const override
 Draw the legend item.
 
void clearLegend ()
 Clear the legend.
 
virtual void updateLegend (const QwtPlotItem *, const QList< QwtLegendData > &) override
 Update the legend.
 
virtual QRect geometry (const QRectF &canvasRect) const
 Get the geometry.
 
virtual QSize minimumSize (const QwtLegendData &) const
 Get the minimum size.
 
virtual int heightForWidth (const QwtLegendData &, int width) const
 Get the height for width.
 
QList< const QwtPlotItem * > plotItems () const
 Get the plot items.
 
QList< QRect > legendGeometries (const QwtPlotItem *) const
 Get the legend geometries.
 
- Public Member Functions inherited from QwtPlotItem
 QwtPlotItem ()
 Default constructor.
 
 QwtPlotItem (const QString &title)
 Constructor with title as QString.
 
 QwtPlotItem (const QwtText &title)
 Constructor with title as QwtText.
 
virtual ~QwtPlotItem ()
 Destructor.
 
virtual void attach (QwtPlot *plot)
 Attach the item to a plot.
 
void detach ()
 Detach the item from the plot.
 
QwtPlotplot () const
 Get the plot the item is attached to.
 
void setTitle (const QString &title)
 Set the title using a QString.
 
void setTitle (const QwtText &title)
 Set the title using a QwtText.
 
const QwtTexttitle () const
 Get the title.
 
void setItemAttribute (ItemAttribute, bool on=true)
 Set an item attribute.
 
bool testItemAttribute (ItemAttribute) const
 Test an item attribute.
 
void setItemInterest (ItemInterest, bool on=true)
 Set an item interest.
 
bool testItemInterest (ItemInterest) const
 Test an item interest.
 
void setRenderHint (RenderHint, bool on=true)
 Set a render hint.
 
bool testRenderHint (RenderHint) const
 Test a render hint.
 
void setRenderThreadCount (uint numThreads)
 Set the number of render threads.
 
uint renderThreadCount () const
 Get the number of render threads.
 
void setLegendIconSize (const QSize &)
 Set the legend icon size.
 
QSize legendIconSize () const
 Get the legend icon size.
 
double z () const
 Get the z-value.
 
void setZ (double z)
 Set the z-value.
 
void show ()
 Show the item.
 
void hide ()
 Hide the item.
 
virtual void setVisible (bool)
 Set the visibility.
 
bool isVisible () const
 Check if the item is visible.
 
void setAxes (QwtAxisId xAxis, QwtAxisId yAxis)
 Set both axes.
 
void setXAxis (QwtAxisId)
 Set the x-axis.
 
QwtAxisId xAxis () const
 Get the x-axis.
 
void setYAxis (QwtAxisId)
 Set the y-axis.
 
QwtAxisId yAxis () const
 Get the y-axis.
 
virtual void itemChanged ()
 Notify the plot that the item has changed.
 
virtual void legendChanged ()
 Notify the item that the legend has changed.
 
virtual QRectF boundingRect () const
 Get the bounding rectangle.
 
virtual void getCanvasMarginHint (const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, double &left, double &top, double &right, double &bottom) const
 Get margin hints for the canvas.
 
virtual void updateScaleDiv (const QwtScaleDiv &, const QwtScaleDiv &)
 Update the item with new scale divisions.
 
QRectF scaleRect (const QwtScaleMap &, const QwtScaleMap &) const
 Calculate the scale rectangle.
 
QRectF paintRect (const QwtScaleMap &, const QwtScaleMap &) const
 Calculate the paint rectangle.
 
virtual QList< QwtLegendDatalegendData () const
 Return legend data.
 
virtual QwtGraphic legendIcon (int index, const QSizeF &) const
 Return a legend icon.
 

Protected Member Functions

virtual void drawLegendData (QPainter *, const QwtPlotItem *, const QwtLegendData &, const QRectF &) const
 Draw the legend data.
 
virtual void drawBackground (QPainter *, const QRectF &rect) const
 Draw the background.
 
- Protected Member Functions inherited from QwtPlotItem
QwtGraphic defaultIcon (const QBrush &, const QSizeF &) const
 Create a default icon.
 

Detailed Description

A class which draws a legend inside the plot canvas.

QwtPlotLegendItem can be used to draw a legend inside the plot canvas. It can be used together with a QwtLegend or instead of it to have more space for the plot canvas.

In opposite to QwtLegend the legend item is not interactive. To identify mouse clicks on a legend item an event filter needs to be installed catching mouse events on the plot canvas. The geometries of the legend items are available using legendGeometries().

The legend item is aligned to plot canvas according to its alignment() flags. It might have a background for the complete legend ( usually semi transparent ) or for each legend item.

Note
An external QwtLegend with a transparent background on top the plot canvas might be another option with a similar effect.

Member Enumeration Documentation

◆ BackgroundMode

Background mode.

Depending on the mode the complete legend or each item might have an background.

The default setting is LegendBackground.

See also
setBackgroundMode(), setBackgroundBrush(), drawBackground()
Enumerator
LegendBackground 

The legend has a background.

ItemBackground 

Each item has a background.

Constructor & Destructor Documentation

◆ QwtPlotLegendItem()

QwtPlotLegendItem::QwtPlotLegendItem ( )
explicit

Constructor.

Creates a legend item with default settings. The legend item is initialized with LegendInterest enabled and a z-value of 100.0.

Destructor

Member Function Documentation

◆ alignmentInCanvas()

Qt::Alignment QwtPlotLegendItem::alignmentInCanvas ( ) const

Get the alignment in canvas.

Get the alignment flags.

Returns
Alignment flags
See also
setAlignmentInCanvas()

◆ backgroundBrush()

QBrush QwtPlotLegendItem::backgroundBrush ( ) const

Get the background brush.

Get the brush used to fill the background.

Returns
Brush used to fill the background
See also
setBackgroundBrush(), backgroundMode(), drawBackground()

◆ backgroundMode()

QwtPlotLegendItem::BackgroundMode QwtPlotLegendItem::backgroundMode ( ) const

Get the background mode.

Returns
Background mode
See also
setBackgroundMode(), backgroundBrush(), drawBackground()

◆ borderPen()

QPen QwtPlotLegendItem::borderPen ( ) const

Get the border pen.

Get the pen for drawing the border.

Returns
Pen for drawing the border
See also
setBorderPen(), backgroundBrush()

◆ borderRadius()

double QwtPlotLegendItem::borderRadius ( ) const

Get the border radius.

Get the radius of the border.

Returns
Radius of the border
See also
setBorderRadius(), setBorderPen()

◆ clearLegend()

void QwtPlotLegendItem::clearLegend ( )

Clear the legend.

Remove all items from the legend.

◆ draw()

void QwtPlotLegendItem::draw ( QPainter *  painter,
const QwtScaleMap xMap,
const QwtScaleMap yMap,
const QRectF &  canvasRect 
) const
overridevirtual

Draw the legend item.

Draw the legend.

Parameters
[in]painterPainter
[in]xMapX Scale Map
[in]yMapY Scale Map
[in]canvasRectContents rectangle of the canvas in painter coordinates

Implements QwtPlotItem.

◆ drawBackground()

void QwtPlotLegendItem::drawBackground ( QPainter *  painter,
const QRectF &  rect 
) const
protectedvirtual

Draw the background.

Draw a rounded rect.

Parameters
painterPainter
rectBounding rectangle
See also
setBorderRadius(), setBorderPen(), setBackgroundBrush(), setBackgroundMode()

◆ drawLegendData()

void QwtPlotLegendItem::drawLegendData ( QPainter *  painter,
const QwtPlotItem plotItem,
const QwtLegendData data,
const QRectF &  rect 
) const
protectedvirtual

Draw the legend data.

Draw an entry on the legend.

Parameters
painterQt Painter
plotItemPlot item, represented by the entry
dataAttributes of the legend entry
rectBounding rectangle for the entry

◆ font()

QFont QwtPlotLegendItem::font ( ) const

Get the font.

Get the font used for drawing the text label.

Returns
Font used for drawing the text label
See also
setFont()

◆ geometry()

QRect QwtPlotLegendItem::geometry ( const QRectF &  canvasRect) const
virtual

Get the geometry.

Calculate the geometry of the legend on the canvas.

Parameters
[in]canvasRectGeometry of the canvas
Returns
Geometry of the legend

◆ heightForWidth()

int QwtPlotLegendItem::heightForWidth ( const QwtLegendData data,
int  width 
) const
virtual

Get the height for width.

Get the preferred height for a given width.

Parameters
[in]dataAttributes of the legend entry
[in]widthWidth
Returns
The preferred height

◆ itemMargin()

int QwtPlotLegendItem::itemMargin ( ) const

Get the item margin.

Get the margin around each item.

Returns
Margin around each item
See also
setItemMargin(), itemSpacing(), margin(), spacing()

◆ itemSpacing()

int QwtPlotLegendItem::itemSpacing ( ) const

Get the item spacing.

Get the spacing inside of each item.

Returns
Spacing inside of each item
See also
setItemSpacing(), itemMargin(), margin(), spacing()

◆ legendGeometries()

QList< QRect > QwtPlotLegendItem::legendGeometries ( const QwtPlotItem plotItem) const

Get the legend geometries.

Get geometries of the items of a plot item.

Parameters
[in]plotItemPlot item
Returns
Geometries of the items of a plot item
Note
Usually a plot item has only one entry on the legend

◆ margin()

int QwtPlotLegendItem::margin ( ) const

Get the margin.

Get the margin around the legend items.

Returns
Margin around the legend items
See also
setMargin(), spacing(), itemMargin(), itemSpacing()

◆ maxColumns()

uint QwtPlotLegendItem::maxColumns ( ) const

Get the maximum number of columns.

Returns
Maximum number of columns
See also
setMaxColumns(), QwtDynGridLayout::maxColumns()

◆ minimumSize()

QSize QwtPlotLegendItem::minimumSize ( const QwtLegendData data) const
virtual

Get the minimum size.

Get the minimum size hint needed to display an entry.

Parameters
[in]dataAttributes of the legend entry
Returns
Minimum size

◆ offsetInCanvas()

int QwtPlotLegendItem::offsetInCanvas ( Qt::Orientation  orientation) const

Get the offset in canvas.

Get the distance between the legend and the canvas border.

Parameters
[in]orientationQt::Horizontal is for the left/right, Qt::Vertical for the top/bottom padding.
Returns
Distance between the legend and the canvas border
See also
setOffsetInCanvas()

◆ plotItems()

QList< const QwtPlotItem * > QwtPlotLegendItem::plotItems ( ) const

Get the plot items.

Get all plot items with an entry on the legend.

Returns
All plot items with an entry on the legend
Note
A plot item might have more than one entry on the legend

◆ rtti()

int QwtPlotLegendItem::rtti ( ) const
overridevirtual

Get the runtime type information.

Returns
QwtPlotItem::Rtti_PlotLegend

Reimplemented from QwtPlotItem.

◆ setAlignmentInCanvas()

void QwtPlotLegendItem::setAlignmentInCanvas ( Qt::Alignment  alignment)

Set the alignment in canvas.

Set the alignment of the legend within the canvas.

Parameters
[in]alignmentAlignment flags (e.g., Qt::AlignRight | Qt::AlignBottom)

Alignment means the position of the legend relative to the geometry of the plot canvas.

Note
To align a legend with many items horizontally, the number of columns needs to be limited.
See also
alignmentInCanvas(), setMaxColumns()

◆ setBackgroundBrush()

void QwtPlotLegendItem::setBackgroundBrush ( const QBrush &  brush)

Set the background brush.

Parameters
[in]brushBrush used to fill the background
See also
backgroundBrush(), setBackgroundMode(), drawBackground()

◆ setBackgroundMode()

void QwtPlotLegendItem::setBackgroundMode ( BackgroundMode  mode)

Set the background mode.

Parameters
[in]modeBackground mode

Depending on the mode the complete legend or each item might have a background. The default setting is LegendBackground.

See also
backgroundMode(), setBackgroundBrush(), drawBackground()

◆ setBorderPen()

void QwtPlotLegendItem::setBorderPen ( const QPen &  pen)

Set the border pen.

Set the pen for drawing the border.

Parameters
[in]penBorder pen
See also
borderPen(), setBackgroundBrush()

◆ setBorderRadius()

void QwtPlotLegendItem::setBorderRadius ( double  radius)

Set the border radius.

Set the radius for the border.

Parameters
[in]radiusA value <= 0 defines a rectangular border
See also
borderRadius(), setBorderPen()

◆ setFont()

void QwtPlotLegendItem::setFont ( const QFont &  font)

Set the font.

Change the font used for drawing the text label.

Parameters
[in]fontLegend font
See also
font()

◆ setItemMargin()

void QwtPlotLegendItem::setItemMargin ( int  margin)

Set the item margin.

Set the margin around each item.

Parameters
[in]marginMargin
See also
itemMargin(), setItemSpacing(), setMargin(), setSpacing()

◆ setItemSpacing()

void QwtPlotLegendItem::setItemSpacing ( int  spacing)

Set the item spacing.

Set the spacing inside of each item.

Parameters
[in]spacingSpacing
See also
itemSpacing(), setItemMargin(), setMargin(), setSpacing()

◆ setMargin()

void QwtPlotLegendItem::setMargin ( int  margin)

Set the margin.

Set the margin around legend items.

Parameters
[in]marginMargin in pixels

The default setting for the margin is 0.

See also
margin(), setSpacing(), setItemMargin(), setItemSpacing

◆ setMaxColumns()

void QwtPlotLegendItem::setMaxColumns ( uint  maxColumns)

Set the maximum number of columns.

Limit the number of columns.

Parameters
[in]maxColumnsMaximum number of columns. 0 means unlimited.

When aligning the legend horizontally (Qt::AlignLeft, Qt::AlignRight), the number of columns needs to be limited to avoid the width of the legend growing with an increasing number of entries.

See also
maxColumns(), QwtDynGridLayout::setMaxColumns()

◆ setOffsetInCanvas()

void QwtPlotLegendItem::setOffsetInCanvas ( Qt::Orientations  orientations,
int  numPixels 
)

Set the offset in canvas.

Set the distance between the legend and the canvas border.

Parameters
[in]orientationsQt::Horizontal is for the left/right, Qt::Vertical for the top/bottom offset.
[in]numPixelsDistance in pixels

The default setting is 10 pixels.

See also
setMargin()

◆ setSpacing()

void QwtPlotLegendItem::setSpacing ( int  spacing)

Set the spacing.

Set the spacing between the legend items.

Parameters
[in]spacingSpacing in pixels
See also
spacing(), setMargin()

◆ setTextPen()

void QwtPlotLegendItem::setTextPen ( const QPen &  pen)

Set the text pen.

Set the pen for drawing text labels.

Parameters
[in]penText pen
See also
textPen(), setFont()

◆ spacing()

int QwtPlotLegendItem::spacing ( ) const

Get the spacing.

Get the spacing between the legend items.

Returns
Spacing between the legend items
See also
setSpacing(), margin(), itemSpacing(), itemMargin()

◆ textPen()

QPen QwtPlotLegendItem::textPen ( ) const

Get the text pen.

Get the pen for drawing text labels.

Returns
Pen for drawing text labels
See also
setTextPen(), font()

◆ updateLegend()

void QwtPlotLegendItem::updateLegend ( const QwtPlotItem plotItem,
const QList< QwtLegendData > &  data 
)
overridevirtual

Update the legend.

Update the legend items according to modifications of a plot item.

Parameters
[in]plotItemPlot item
[in]dataAttributes of the legend entries

Reimplemented from QwtPlotItem.


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