Qwt User's Guide  6.1.3
QwtPlotLegendItem Class Reference

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

#include <qwt_plot_legenditem.h>

Inheritance diagram for QwtPlotLegendItem:

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_PlotSVG, Rtti_PlotTradingCurve,
  Rtti_PlotBarChart, Rtti_PlotMultiBarChart, Rtti_PlotShape, Rtti_PlotTextLabel,
  Rtti_PlotZone, 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...
typedef QFlags< ItemAttributeItemAttributes
 Plot Item Attributes.
typedef QFlags< ItemInterestItemInterests
 Plot Item Interests.
typedef QFlags< RenderHintRenderHints
 Render hints.

Public Member Functions

 QwtPlotLegendItem ()
virtual ~QwtPlotLegendItem ()
virtual int rtti () const
void setAlignment (Qt::Alignment)
 Set the alignmnet. More...
Qt::Alignment alignment () const
void setMaxColumns (uint)
 Limit the number of columns. More...
uint maxColumns () const
void setMargin (int)
 Set the margin around legend items. More...
int margin () const
void setSpacing (int)
 Set the spacing between the legend items. More...
int spacing () const
void setItemMargin (int)
int itemMargin () const
void setItemSpacing (int)
int itemSpacing () const
void setFont (const QFont &)
QFont font () const
void setBorderDistance (int numPixels)
 Set the margin between the legend and the canvas border. More...
int borderDistance () const
void setBorderRadius (double)
double borderRadius () const
void setBorderPen (const QPen &)
QPen borderPen () const
void setBackgroundBrush (const QBrush &)
 Set the background brush. More...
QBrush backgroundBrush () const
void setBackgroundMode (BackgroundMode)
 Set the background mode. More...
BackgroundMode backgroundMode () const
void setTextPen (const QPen &)
 Set the pen for drawing text labels. More...
QPen textPen () const
virtual void draw (QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &rect) const
void clearLegend ()
 Remove all items from the legend.
virtual void updateLegend (const QwtPlotItem *, const QList< QwtLegendData > &)
virtual QRect geometry (const QRectF &canvasRect) const
virtual QSize minimumSize (const QwtLegendData &) const
virtual int heightForWidth (const QwtLegendData &, int w) const
QList< const QwtPlotItem * > plotItems () const
QList< QRect > legendGeometries (const QwtPlotItem *) const
- Public Member Functions inherited from QwtPlotItem
 QwtPlotItem (const QwtText &title=QwtText())
virtual ~QwtPlotItem ()
 Destroy the QwtPlotItem.
void attach (QwtPlot *plot)
 Attach the item to a plot. More...
void detach ()
 This method detaches a QwtPlotItem from any QwtPlot it has been associated with. More...
QwtPlotplot () const
 Return attached plot.
void setTitle (const QString &title)
void setTitle (const QwtText &title)
const QwtTexttitle () const
void setItemAttribute (ItemAttribute, bool on=true)
bool testItemAttribute (ItemAttribute) const
void setItemInterest (ItemInterest, bool on=true)
bool testItemInterest (ItemInterest) const
void setRenderHint (RenderHint, bool on=true)
bool testRenderHint (RenderHint) const
void setRenderThreadCount (uint numThreads)
uint renderThreadCount () const
void setLegendIconSize (const QSize &)
QSize legendIconSize () const
double z () const
void setZ (double z)
 Set the z value. More...
void show ()
 Show the item.
void hide ()
 Hide the item.
virtual void setVisible (bool)
bool isVisible () const
void setAxes (int xAxis, int yAxis)
void setXAxis (int axis)
int xAxis () const
 Return xAxis.
void setYAxis (int axis)
int yAxis () const
 Return yAxis.
virtual void itemChanged ()
virtual void legendChanged ()
virtual QRectF boundingRect () const
virtual void getCanvasMarginHint (const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasSize, double &left, double &top, double &right, double &bottom) const
 Calculate a hint for the canvas margin. More...
virtual void updateScaleDiv (const QwtScaleDiv &, const QwtScaleDiv &)
 Update the item to changes of the axes scale division. More...
QRectF scaleRect (const QwtScaleMap &, const QwtScaleMap &) const
 Calculate the bounding scale rectangle of 2 maps. More...
QRectF paintRect (const QwtScaleMap &, const QwtScaleMap &) const
 Calculate the bounding paint rectangle of 2 maps. More...
virtual QList< QwtLegendDatalegendData () const
 Return all information, that is needed to represent the item on the legend. More...
virtual QwtGraphic legendIcon (int index, const QSizeF &) const

Protected Member Functions

virtual void drawLegendData (QPainter *painter, const QwtPlotItem *, const QwtLegendData &, const QRectF &) const
virtual void drawBackground (QPainter *, const QRectF &rect) const
- Protected Member Functions inherited from QwtPlotItem
QwtGraphic defaultIcon (const QBrush &, const QSizeF &) const
 Return a default icon from a brush. More...

Detailed Description

A class which draws a legend inside the plot canvas.

QwtPlotLegendItem can be used to draw a 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 ob 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.

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

Member Enumeration Documentation

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()

The legend has a background.


Each item has a background.

Member Function Documentation

Qt::Alignment QwtPlotLegendItem::alignment ( ) const
Alignment flags
See also
QBrush QwtPlotLegendItem::backgroundBrush ( ) const
Brush is used to fill the background
See also
setBackgroundBrush(), backgroundMode(), drawBackground()
QwtPlotLegendItem::BackgroundMode QwtPlotLegendItem::backgroundMode ( ) const
See also
setBackgroundMode(), backgroundBrush(), drawBackground()
int QwtPlotLegendItem::borderDistance ( ) const
Margin between the legend and the canvas border
See also
QPen QwtPlotLegendItem::borderPen ( ) const
Pen for drawing the border
See also
setBorderPen(), backgroundBrush()
double QwtPlotLegendItem::borderRadius ( ) const
Radius of the border
See also
setBorderRadius(), setBorderPen()
void QwtPlotLegendItem::draw ( QPainter *  painter,
const QwtScaleMap xMap,
const QwtScaleMap yMap,
const QRectF &  canvasRect 
) const

Draw the legend

xMapx Scale Map
yMapy Scale Map
canvasRectContents rectangle of the canvas in painter coordinates

Implements QwtPlotItem.

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

Draw a rounded rect

rectBounding rectangle
See also
setBorderRadius(), setBorderPen(), setBackgroundBrush(), setBackgroundMode()
void QwtPlotLegendItem::drawLegendData ( QPainter *  painter,
const QwtPlotItem plotItem,
const QwtLegendData data,
const QRectF &  rect 
) const

Draw an entry on the legend

painterQt Painter
plotItemPlot item, represented by the entry
dataAttributes of the legend entry
rectBounding rectangle for the entry
QFont QwtPlotLegendItem::font ( ) const
Font used for drawing the text label
See also
QRect QwtPlotLegendItem::geometry ( const QRectF &  canvasRect) const

Calculate the geometry of the legend on the canvas

canvasRectGeometry of the canvas
Geometry of the legend
int QwtPlotLegendItem::heightForWidth ( const QwtLegendData data,
int  width 
) const
The preferred height, for a width.
dataAttributes of the legend entry
int QwtPlotLegendItem::itemMargin ( ) const
Margin around each item
See also
setItemMargin(), itemSpacing(), margin(), spacing()
int QwtPlotLegendItem::itemSpacing ( ) const
Spacing inside of each item
See also
setItemSpacing(), itemMargin(), margin(), spacing()
QList< QRect > QwtPlotLegendItem::legendGeometries ( const QwtPlotItem plotItem) const
Geometries of the items of a plot item
Usually a plot item has only one entry on the legend
int QwtPlotLegendItem::margin ( ) const
Margin around the legend items
See also
setMargin(), spacing(), itemMargin(), itemSpacing()
uint QwtPlotLegendItem::maxColumns ( ) const
Maximum number of columns
See also
maxColumns(), QwtDynGridLayout::maxColumns()
QSize QwtPlotLegendItem::minimumSize ( const QwtLegendData data) const

Minimum size hint needed to display an entry

dataAttributes of the legend entry
Minimum size
QList< const QwtPlotItem * > QwtPlotLegendItem::plotItems ( ) const
All plot items with an entry on the legend
A plot item might have more than one entry on the legend
int QwtPlotLegendItem::rtti ( ) const

Reimplemented from QwtPlotItem.

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

Set the alignmnet.

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

alignmentAlignment flags
See also
alignment(), setMaxColumns()
To align a legend with many items horizontally the number of columns need to be limited
void QwtPlotLegendItem::setBackgroundBrush ( const QBrush &  brush)

Set the background brush.

The brush is used to fill the background

See also
backgroundBrush(), setBackgroundMode(), drawBackground()
void QwtPlotLegendItem::setBackgroundMode ( BackgroundMode  mode)

Set the background mode.

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

The default setting is LegendBackground.

See also
backgroundMode(), setBackgroundBrush(), drawBackground()
void QwtPlotLegendItem::setBorderDistance ( int  distance)

Set the margin between the legend and the canvas border.

The default setting for the margin is 10 pixels.

distanceMargin in pixels
See also
void QwtPlotLegendItem::setBorderPen ( const QPen &  pen)

Set the pen for drawing the border

penBorder pen
See also
borderPen(), setBackgroundBrush()
void QwtPlotLegendItem::setBorderRadius ( double  radius)

Set the radius for the border

radiusA value <= 0 defines a rectangular border
See also
borderRadius(), setBorderPen()
void QwtPlotLegendItem::setFont ( const QFont &  font)

Change the font used for drawing the text label

fontLegend font
See also
void QwtPlotLegendItem::setItemMargin ( int  margin)

Set the margin around each item

See also
itemMargin(), setItemSpacing(), setMargin(), setSpacing()
void QwtPlotLegendItem::setItemSpacing ( int  spacing)

Set the spacing inside of each item

See also
itemSpacing(), setItemMargin(), setMargin(), setSpacing()
void QwtPlotLegendItem::setMargin ( int  margin)

Set the margin around legend items.

The default setting for the margin is 0.

marginMargin in pixels
See also
margin(), setSpacing(), setItemMargin(), setItemSpacing
void QwtPlotLegendItem::setMaxColumns ( uint  maxColumns)

Limit the number of columns.

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

maxColumnsMaximum number of columns. 0 means unlimited.
See also
maxColumns(), QwtDynGridLayout::setMaxColumns()
void QwtPlotLegendItem::setSpacing ( int  spacing)

Set the spacing between the legend items.

spacingSpacing in pixels
See also
spacing(), setMargin()
void QwtPlotLegendItem::setTextPen ( const QPen &  pen)

Set the pen for drawing text labels.

penText pen
See also
textPen(), setFont()
int QwtPlotLegendItem::spacing ( ) const
Spacing between the legend items
See also
setSpacing(), margin(), itemSpacing(), itemMargin()
QPen QwtPlotLegendItem::textPen ( ) const
Pen for drawing text labels
See also
setTextPen(), font()
void QwtPlotLegendItem::updateLegend ( const QwtPlotItem plotItem,
const QList< QwtLegendData > &  data 

Update the legend items according to modifications of a plot item

plotItemPlot item
dataAttributes of the legend entries

Reimplemented from QwtPlotItem.