QLegend Class

The QLegend class displays the legend of a chart. More...

Header: #include <QLegend>
Instantiated By: Legend
Inherits: QGraphicsWidget

Public Types

enum MarkerShape { MarkerShapeDefault, MarkerShapeRectangle, MarkerShapeCircle, MarkerShapeFromSeries }

Properties

Public Functions

Qt::Alignment alignment() const
QColor borderColor()
QColor color()
QFont font() const
bool isBackgroundVisible() const
QColor labelColor() const
QLegend::MarkerShape markerShape() const
bool reverseMarkers()
void setAlignment(Qt::Alignment alignment)
void setBackgroundVisible(bool visible = true)
void setBorderColor(QColor color)
void setColor(QColor color)
void setFont(const QFont &font)
void setLabelColor(QColor color)
void setMarkerShape(QLegend::MarkerShape shape)
void setReverseMarkers(bool reverseMarkers = true)
void setShowToolTips(bool show)
bool showToolTips() const

Signals

void backgroundVisibleChanged(bool visible)
void borderColorChanged(QColor color)
void colorChanged(QColor color)
void fontChanged(QFont font)
void labelColorChanged(QColor color)
void markerShapeChanged(QLegend::MarkerShape shape)
void reverseMarkersChanged(bool reverseMarkers)
void showToolTipsChanged(bool showToolTips)

Detailed Description

A legend is a graphical object that displays the legend of a chart. The legend state is updated by QChart when series change. By default, the legend is attached to the chart, but it can be detached to make it independent of chart layout. Legend objects cannot be created or deleted, but they can be referenced via the QChart class.

See also QChart.

Member Type Documentation

enum QLegend::MarkerShape

This enum describes the shape used when rendering legend marker items.

ConstantValueDescription
QLegend::MarkerShapeDefault0Default shape determined by QLegend is used for the marker. This value is supported only for individual QLegendMarker items.
QLegend::MarkerShapeRectangle1Rectangular markers are used. Marker size is determined by font size.
QLegend::MarkerShapeCircle2Circular markers are used. Marker size is determined by font size.
QLegend::MarkerShapeFromSeries3The marker shape is determined by the series. In case of a scatter series, the legend marker looks like a scatter dot and is the same size as the dot. In case of a line or spline series, the legend marker looks like a small segment of the line. For other series types, rectangular markers are shown.

See also markerShape.

Property Documentation

alignment : Qt::Alignment

How the legend is aligned with the chart.

Can be Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag, the result is undefined.

Access functions:

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

backgroundVisible : bool

This property holds whether the legend background is visible.

Access functions:

bool isBackgroundVisible() const
void setBackgroundVisible(bool visible = true)

Notifier signal:

void backgroundVisibleChanged(bool visible)

borderColor : QColor

This property holds the line color of the legend.

Access functions:

QColor borderColor()
void setBorderColor(QColor color)

Notifier signal:

void borderColorChanged(QColor color)

color : QColor

This property holds the background (brush) color of the legend.

If you change the color of the legend, the style of the legend brush is set to Qt::SolidPattern.

Access functions:

QColor color()
void setColor(QColor color)

Notifier signal:

void colorChanged(QColor color)

font : QFont

This property holds the font of the markers used by the legend.

Access functions:

QFont font() const
void setFont(const QFont &font)

Notifier signal:

void fontChanged(QFont font)

labelColor : QColor

This property holds the color of the brush used to draw labels.

Access functions:

QColor labelColor() const
void setLabelColor(QColor color)

Notifier signal:

void labelColorChanged(QColor color)

markerShape : MarkerShape

The default shape of the legend markers. The default value is MarkerShapeRectangle.

This property was introduced in Qt 5.9.

Access functions:

QLegend::MarkerShape markerShape() const
void setMarkerShape(QLegend::MarkerShape shape)

Notifier signal:

void markerShapeChanged(QLegend::MarkerShape shape)

reverseMarkers : bool

This property holds whether reverse order is used for the markers in the legend.

This property is false by default.

Access functions:

bool reverseMarkers()
void setReverseMarkers(bool reverseMarkers = true)

Notifier signal:

void reverseMarkersChanged(bool reverseMarkers)

showToolTips : bool

This property holds whether tooltips are shown when the text is truncated.

This property is false by default.

Access functions:

bool showToolTips() const
void setShowToolTips(bool show)

Notifier signal:

void showToolTipsChanged(bool showToolTips)