QLegend Class
The QLegend class is the legend of a chart. More…
| Header | #include <QLegend> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Charts) |
| Module | Nt Charts C++ Classes |
| Inherits | QObject |
List of all members, including inherited members
Public Types
| enum | MarkerShape |
Public Functions
| ~QLegend() | |
| void | setBrush(const QBrush &brush) |
| QBrush | brush() const |
| void | setColor(QColor color) |
| QColor | color() |
| void | setPen(const QPen &pen) |
| QPen | pen() const |
| void | setBorderColor(QColor color) |
| QColor | borderColor() |
| void | setFont(const QFont &font) |
| QFont | font() const |
| void | setLabelBrush(const QBrush &brush) |
| QBrush | labelBrush() const |
| void | setLabelColor(QColor color) |
| QColor | labelColor() const |
| void | setAlignment(Qt::Alignment alignment) |
| Qt::Alignment | alignment() const |
| void | setVisible(bool visible) |
| bool | isVisible() const |
| void | show() |
| void | hide() |
| void | setBackgroundVisible(bool visible = true) |
| bool | isBackgroundVisible() const |
| void | setReverseMarkers(bool reverseMarkers = true) |
| bool | reverseMarkers() |
| void | setShowToolTips(bool show) |
| bool | showToolTips() const |
| MarkerShape | markerShape() const |
| void | setMarkerShape(MarkerShape shape) |
Signals
| void | backgroundVisibleChanged(bool visible) |
| void | colorChanged(QColor color) |
| void | borderColorChanged(QColor color) |
| void | fontChanged(QFont font) |
| void | labelColorChanged(QColor color) |
| void | reverseMarkersChanged(bool reverseMarkers) |
| void | showToolTipsChanged(bool showToolTips) |
| void | markerShapeChanged(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.
| Constant | Description |
|---|---|
QLegend::MarkerShapeDefault | The shape of the legend: rectangles. |
QLegend::MarkerShapeRectangle | A square. |
QLegend::MarkerShapeCircle | A circle. |
QLegend::MarkerShapeFromSeries | A short line for line and spline series, the marker shape for scatter series, and a square for the others. |
QLegend::MarkerShapeRotatedRectangle | A square standing on a corner; Nt draws a square. |
QLegend::MarkerShapeTriangle | A triangle; Nt draws a square. |
QLegend::MarkerShapeStar | A star; Nt draws a square. |
QLegend::MarkerShapePentagon | A pentagon; Nt draws a square. |
Member Function Documentation
QLegend::~QLegend()
Destroys the legend. The chart does it.
Qt::Alignment QLegend::alignment() const
Returns the side of the chart the legend is on.
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.
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.
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.
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.
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.
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.
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.
void QLegend::showToolTipsChanged(bool showToolTips)
This signal is emitted when tool tips are turned on or off; showToolTips is the new state.