QLegend Class
The QLegend class displays the legend of a chart. 更多...
头文件: | #include <QLegend> |
Instantiated By: | Legend |
基类: | QGraphicsWidget |
公有类型
enum | MarkerShape { MarkerShapeDefault, MarkerShapeRectangle, MarkerShapeCircle, MarkerShapeFromSeries } |
属性
|
|
- 14 个属性继承自 QGraphicsWidget
- 12 个属性继承自 QGraphicsObject
公有函数
~QLegend() | |
Qt::Alignment | alignment() const |
void | attachToChart() |
QColor | borderColor() |
QBrush | brush() const |
QColor | color() |
void | detachFromChart() |
QFont | font() const |
bool | isAttachedToChart() |
bool | isBackgroundVisible() const |
QBrush | labelBrush() const |
QColor | labelColor() const |
MarkerShape | markerShape() const |
QList<QLegendMarker *> | markers(QAbstractSeries *series = Q_NULLPTR) const |
QPen | pen() const |
bool | reverseMarkers() |
void | setAlignment(Qt::Alignment alignment) |
void | setBackgroundVisible(bool visible = true) |
void | setBorderColor(QColor color) |
void | setBrush(const QBrush &brush) |
void | setColor(QColor color) |
void | setFont(const QFont &font) |
void | setLabelBrush(const QBrush &brush) |
void | setLabelColor(QColor color) |
void | setMarkerShape(MarkerShape shape) |
void | setPen(const QPen &pen) |
void | setReverseMarkers(bool reverseMarkers = true) |
void | setShowToolTips(bool show) |
bool | showToolTips() const |
- 53 个公有函数继承自 QGraphicsWidget
- 35 个公有函数继承自 QGraphicsLayoutItem
- 2 个公有函数继承自 QGraphicsObject
- 176 个公有函数继承自 QGraphicsItem
信号
void | backgroundVisibleChanged(bool visible) |
void | borderColorChanged(QColor color) |
void | colorChanged(QColor color) |
void | fontChanged(QFont font) |
void | labelColorChanged(QColor color) |
void | markerShapeChanged(MarkerShape shape) |
void | reverseMarkersChanged(bool reverseMarkers) |
void | showToolTipsChanged(bool showToolTips) |
- 1 个信号继承自 QGraphicsWidget
- 9 个信号继承自 QGraphicsObject
其他继承的成员
- 1 个公有槽函数继承自 QGraphicsWidget
- 1 个公有变量继承自 QGraphicsWidget
- 2 个公有变量继承自 QGraphicsItem
- 1 个静态公有成员继承自 QGraphicsWidget
- 24 个受保护的函数继承自 QGraphicsWidget
- 3 个受保护的函数继承自 QGraphicsLayoutItem
- 1 个受保护的函数继承自 QGraphicsObject
- 24 个受保护的函数继承自 QGraphicsItem
- 1 个受保护的槽函数继承自 QGraphicsObject
- 1 protected type inherited from QGraphicsLayoutItem
- 1 protected type inherited from QGraphicsItem
详细描述
The QLegend class displays the legend of a chart.
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.
参见 QChart.
成员类型
enum QLegend::MarkerShape
This enum describes the shape used when rendering legend marker items.
Constant | Value | Description |
---|---|---|
QLegend::MarkerShapeDefault | 0 | Default shape determined by QLegend is used for the marker. This value is supported only for individual QLegendMarker items. |
QLegend::MarkerShapeRectangle | 1 | Rectangular markers are used. Marker size is determined by font size. |
QLegend::MarkerShapeCircle | 2 | Circular markers are used. Marker size is determined by font size. |
QLegend::MarkerShapeFromSeries | 3 | The 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. |
参见 markerShape.
属性
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.
访问函数:
Qt::Alignment | alignment() const |
void | setAlignment(Qt::Alignment alignment) |
backgroundVisible : bool
This property holds whether the legend background is visible.
访问函数:
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.
访问函数:
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.
访问函数:
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.
访问函数:
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.
访问函数:
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.
访问函数:
MarkerShape | markerShape() const |
void | setMarkerShape(MarkerShape shape) |
Notifier signal:
void | markerShapeChanged(MarkerShape shape) |
reverseMarkers : bool
This property holds whether reverse order is used for the markers in the legend.
This property is false
by default.
访问函数:
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.
访问函数:
bool | showToolTips() const |
void | setShowToolTips(bool show) |
Notifier signal:
void | showToolTipsChanged(bool showToolTips) |
成员函数
QLegend::~QLegend()
Destroys the legend object. The legend is always owned by a QChart, so an application should never call this function.
void QLegend::attachToChart()
Attaches the legend to a chart. The chart may adjust the layout of the legend.
[signal]
void QLegend::backgroundVisibleChanged(bool visible)
This signal is emitted when the visibility of the legend background changes to visible.
Note: Notifier signal for property backgroundVisible.
[signal]
void QLegend::borderColorChanged(QColor color)
This signal is emitted when the border color of the legend background changes to color.
Note: Notifier signal for property borderColor.
QBrush QLegend::brush() const
Returns the brush used by the legend.
参见 setBrush().
[signal]
void QLegend::colorChanged(QColor color)
This signal is emitted when the color of the legend background changes to color.
Note: Notifier signal for property color.
void QLegend::detachFromChart()
Detaches the legend from the chart. The chart will no longer adjust the layout of the legend.
[signal]
void QLegend::fontChanged(QFont font)
This signal is emitted when the font of the markers of the legend changes to font.
Note: Notifier signal for property font.
bool QLegend::isAttachedToChart()
Returns true
, if the legend is attached to a chart.
bool QLegend::isBackgroundVisible() const
Returns the visibility of the legend background.
Note: Getter function for property backgroundVisible.
QBrush QLegend::labelBrush() const
Returns the brush used to draw labels.
参见 setLabelBrush().
[signal]
void QLegend::labelColorChanged(QColor color)
This signal is emitted when the color of the brush used to draw the legend labels changes to color.
Note: Notifier signal for property labelColor.
QList<QLegendMarker *> QLegend::markers(QAbstractSeries *series = Q_NULLPTR) const
Returns the list of markers in the legend. The list can be filtered by specifying the series for which the markers are returned.
QPen QLegend::pen() const
Returns the pen used by the legend.
参见 setPen().
[signal]
void QLegend::reverseMarkersChanged(bool reverseMarkers)
This signal is emitted when the use of reverse order for the markers in the legend is changed to reverseMarkers.
Note: Notifier signal for property reverseMarkers.
void QLegend::setBackgroundVisible(bool visible = true)
Sets the visibility of the legend background to visible.
Note: Setter function for property backgroundVisible.
参见 isBackgroundVisible().
void QLegend::setBrush(const QBrush &brush)
Sets the brush that is used to draw the background of the legend.
参见 brush().
void QLegend::setLabelBrush(const QBrush &brush)
Sets the brush used to draw the legend labels to brush.
参见 labelBrush().
void QLegend::setPen(const QPen &pen)
Sets the pen that is used to draw the legend borders.
参见 pen().
void QLegend::setShowToolTips(bool show)
When show is true
, the legend labels will show a tooltip when the mouse hovers over them if the label itself is shown elided. This is false
by default.
Note: Setter function for property showToolTips.
参见 showToolTips().
bool QLegend::showToolTips() const
Returns whether the tooltips are shown for the legend labels when they are elided.
Note: Getter function for property showToolTips.
参见 setShowToolTips().
[signal]
void QLegend::showToolTipsChanged(bool showToolTips)
This signal is emitted when the visibility of tooltips is changed to showToolTips.
Note: Notifier signal for property showToolTips.