6.0.0-rc4Source

QLegend Class

The QLegend class is the legend of a chart. More…

Header#include <QLegend>
CMaketarget_link_libraries(app PRIVATE Nt::Charts)
ModuleNt Charts C++ Classes
InheritsQObject

List of all members, including inherited members

Public Types

Public Functions

~QLegend()
voidsetBrush(const QBrush &brush)
QBrushbrush() const
voidsetColor(QColor color)
QColorcolor()
voidsetPen(const QPen &pen)
QPenpen() const
voidsetBorderColor(QColor color)
QColorborderColor()
voidsetFont(const QFont &font)
QFontfont() const
voidsetLabelBrush(const QBrush &brush)
QBrushlabelBrush() const
voidsetLabelColor(QColor color)
QColorlabelColor() const
voidsetAlignment(Qt::Alignment alignment)
Qt::Alignmentalignment() const
voidsetVisible(bool visible)
boolisVisible() const
voidshow()
voidhide()
voidsetBackgroundVisible(bool visible = true)
boolisBackgroundVisible() const
voidsetReverseMarkers(bool reverseMarkers = true)
boolreverseMarkers()
voidsetShowToolTips(bool show)
boolshowToolTips() const
MarkerShapemarkerShape() const
voidsetMarkerShape(MarkerShape shape)

Signals

voidbackgroundVisibleChanged(bool visible)
voidcolorChanged(QColor color)
voidborderColorChanged(QColor color)
voidfontChanged(QFont font)
voidlabelColorChanged(QColor color)
voidreverseMarkersChanged(bool reverseMarkers)
voidshowToolTipsChanged(bool showToolTips)
voidmarkerShapeChanged(QLegend::MarkerShape shape)

Detailed Description

The legend has an entry for each series that is drawn: one per line, spline, scatter or area series, one per set of a bar series and one per slice of a pie series. Each entry has a marker in the color of the series and its name. The chart owns its legend; get it with QChart::legend():

chart->legend()->setAlignment(Qt::AlignBottom);
chart->legend()->setMarkerShape(QLegend::MarkerShapeCircle);

See also QChart.

Differences from Qt

The legend is a QObject, not a graphics item: it cannot be detached from the chart or moved, and has no QLegendMarker objects. MarkerShapeRotatedRectangle, MarkerShapeTriangle, MarkerShapeStar and MarkerShapePentagon are drawn as rectangles. Tool tips are not shown.

Member Type Documentation

enum QLegend::MarkerShape

The shape of the markers.

ConstantDescription
QLegend::MarkerShapeDefaultThe shape of the legend: rectangles.
QLegend::MarkerShapeRectangleA square.
QLegend::MarkerShapeCircleA circle.
QLegend::MarkerShapeFromSeriesA short line for line and spline series, the marker shape for scatter series, and a square for the others.
QLegend::MarkerShapeRotatedRectangleA square standing on a corner; Nt draws a square.
QLegend::MarkerShapeTriangleA triangle; Nt draws a square.
QLegend::MarkerShapeStarA star; Nt draws a square.
QLegend::MarkerShapePentagonA pentagon; Nt draws a square.

Member Function Documentation

[override] QLegend::~QLegend()

Destroys the legend. The chart does it.

Qt::Alignment QLegend::alignment() const

Returns the side of the chart the legend is on.

[signal] void QLegend::backgroundVisibleChanged(bool visible)

This signal is emitted when the background is shown or hidden; visible is the new state.

QColor QLegend::borderColor()

Returns the color of the border.

[signal] void QLegend::borderColorChanged(QColor color)

This signal is emitted when the border color changes to color.

QBrush QLegend::brush() const

Returns the brush of the background.

QColor QLegend::color()

Returns the color of the background.

[signal] void QLegend::colorChanged(QColor color)

This signal is emitted when the background color changes to color.

QFont QLegend::font() const

Returns the font of the labels.

[signal] void QLegend::fontChanged(QFont font)

This signal is emitted when the font changes to font.

void QLegend::hide()

Hides the legend.

bool QLegend::isBackgroundVisible() const

Returns true if the background is drawn; otherwise returns false.

bool QLegend::isVisible() const

Returns true if the legend is drawn; otherwise returns false.

QBrush QLegend::labelBrush() const

Returns the brush of the labels.

QColor QLegend::labelColor() const

Returns the color of the labels.

[signal] void QLegend::labelColorChanged(QColor color)

This signal is emitted when the color of the labels changes to color.

MarkerShape QLegend::markerShape() const

Returns the shape of the markers.

[signal] void QLegend::markerShapeChanged(QLegend::MarkerShape shape)

This signal is emitted when the shape of the markers changes to shape.

QPen QLegend::pen() const

Returns the pen of the border.

bool QLegend::reverseMarkers()

Returns true if the entries are listed in reverse order; otherwise returns false.

[signal] void QLegend::reverseMarkersChanged(bool reverseMarkers)

This signal is emitted when the order of the markers is reversed or restored; reverseMarkers is the new state.

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

Puts the legend on the side of the chart given by alignment: Qt::AlignTop (the default), Qt::AlignBottom, Qt::AlignLeft or Qt::AlignRight.

void QLegend::setBackgroundVisible(bool visible = true)

Draws the background and border of the legend if visible is true.

void QLegend::setBorderColor(QColor color)

Sets the color of the border to color.

void QLegend::setBrush(const QBrush &brush)

Sets the brush of the background to brush. The background is drawn when isBackgroundVisible() is true.

void QLegend::setColor(QColor color)

Sets the color of the background to color.

void QLegend::setFont(const QFont &font)

Sets the font of the labels to font.

void QLegend::setLabelBrush(const QBrush &brush)

Sets the brush of the labels to brush.

void QLegend::setLabelColor(QColor color)

Sets the color of the labels to color.

void QLegend::setMarkerShape(MarkerShape shape)

Sets the shape of the markers to shape.

void QLegend::setPen(const QPen &pen)

Sets the pen of the border to pen.

void QLegend::setReverseMarkers(bool reverseMarkers = true)

Lists the entries in reverse order if reverseMarkers is true.

void QLegend::setShowToolTips(bool show)

Sets whether the legend shows tool tips with labels that do not fit to show. Nt keeps the value and shows none.

void QLegend::setVisible(bool visible)

Shows the legend if visible is true and hides it otherwise.

void QLegend::show()

Shows the legend.

bool QLegend::showToolTips() const

Returns true if tool tips were asked for; otherwise returns false.

[signal] void QLegend::showToolTipsChanged(bool showToolTips)

This signal is emitted when tool tips are turned on or off; showToolTips is the new state.