QLegend类
QLegend类显示图表的图例。更多...
| 头文件 | #include <QLegend> | 
| 由以下实例化 | 图例 | 
| 继承自 | QGraphicsWidget | 
公共类型
| 枚举 | MarkerShape { MarkerShapeDefault, MarkerShapeRectangle, MarkerShapeCircle, MarkerShapeRotatedRectangle, MarkerShapeTriangle, …, MarkerShapeFromSeries } | 
属性
| 
 | 
 | 
公共函数
| 虚的 | ~QLegend() | 
| Qt::Alignment | alignment() const | 
| void | attachToChart() | 
| QColor | borderColor() | 
| QBrush | brush() const | 
| QColor | color() | 
| void | detachFromChart() | 
| QFont | font() const | 
| bool | isAttachedToChart() | 
| bool | isBackgroundVisible() const | 
| (since 6.2)bool | isInteractive() const | 
| QBrush | labelBrush() const | 
| QColor | labelColor() const | 
| QLegend::MarkerShape | markerShape() const | 
| QList | markers(QAbstractSeries *series = 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) | 
| (since 6.2)void | setInteractive(bool interactive) | 
| void | setLabelBrush(const QBrush &brush) | 
| void | setLabelColor(QColor color) | 
| void | 设置标记形状(QLegend::MarkerShape shape) | 
| void | 设置画笔(const QPen &pen) | 
| void | 设置反向标记(bool reverseMarkers = true) | 
| void | 设置显示工具提示(bool show) | 
| bool | 显示工具提示() const | 
信号
| (since 6.2)void | 附加到图表变更(bool attached) | 
| void | 背景可见性变更(bool visible) | 
| void | 边框颜色变更(QColor color) | 
| void | 颜色变更(QColor color) | 
| void | 字体变更(QFont font) | 
| void | 标签颜色变更(QColor color) | 
| void | 标记形状变更(QLegend::MarkerShape shape) | 
| void | 反向标记变更(bool reverseMarkers) | 
| void | 显示工具提示变更(bool showToolTips) | 
详细描述
图例是用于显示图表图例的图形对象。图例状态将由 QChart 在系列变化时更新。默认情况下,图例附加到图表上,但它可以被分离出来使其独立于图表布局。图例对象不能被创建或删除,但可以通过 QChart 类进行引用。

另请参阅QChart.
成员类型文档
enum QLegend::MarkerShape
此枚举描述了渲染图例标记项时使用的形状。
| 常数 | 值 | 描述 | 
|---|---|---|
| QLegend::MarkerShapeDefault | 0 | 用于标记的默认形状由 QLegend 确定。此值仅适用于单个 QLegendMarker 项。 | 
| QLegend::MarkerShapeRectangle | 1 | 使用矩形标记。标记大小由字体大小确定。 | 
| QLegend::MarkerShapeCircle | 2 | 使用圆形标记。标记大小由字体大小确定。 | 
| QLegend::MarkerShapeRotatedRectangle | 4 | 使用旋转矩形形状的标记。标记大小由字体大小确定。 | 
| QLegend::MarkerShapeTriangle | 5 | 使用三角形标记。标记大小由字体大小确定。 | 
| QLegend::MarkerShapeStar | 6 | 使用星形标记。标记大小由字体大小确定。 | 
| QLegend::MarkerShapePentagon | 7 | 使用五边形标记。标记大小由字体大小确定。 | 
| QLegend::MarkerShapeFromSeries | 3 | 标记形状由系列确定。对于散点系列,图例标记看起来像一个散点,大小与点相同。对于线或样条系列,图例标记看起来像一条线的小段。对于其他系列类型,将显示矩形标记。如果为系列指定了 lightMarker,则将显示lightMarker,其大小将由系列标记大小确定。 | 
另请参阅markerShape.
属性文档
alignment : Qt::Alignment
图例如何与图表对齐。
可以是 Qt::AlignTop、Qt::AlignBottom、Qt::AlignLeft、Qt::AlignRight。如果您设置了多个标志,则结果是不确定的。
访问函数
| Qt::Alignment | alignment() const | 
| void | setAlignment(Qt::Alignment alignment) | 
backgroundVisible : bool
此属性表示图例背景是否可见。
访问函数
| bool | isBackgroundVisible() const | 
| void | setBackgroundVisible(bool visible = true) | 
通知器信号
| void | backgroundVisibleChanged(bool visible) | 
borderColor : QColor
此属性存储图例的线条颜色。
访问函数
| QColor | borderColor() | 
| void | setBorderColor(QColor color) | 
通知器信号
| void | borderColorChanged(QColor color) | 
color : QColor
此属性存储图例的背景(画刷)颜色。
如果您更改图例的颜色,图例画刷的样式将设置为 Qt::SolidPattern。
访问函数
| QColor | color() | 
| void | setColor(QColor color) | 
通知器信号
| void | colorChanged(QColor color) | 
font : QFont
此属性持有图例使用的标记的字体。
访问函数
| QFont | font() const | 
| void | setFont(const QFont &font) | 
通知器信号
| void | fontChanged(QFont font) | 
labelColor : QColor
此属性存储绘制标签所使用的画刷颜色。
访问函数
| QColor | labelColor() const | 
| void | setLabelColor(QColor color) | 
通知器信号
| void | labelColorChanged(QColor color) | 
markerShape : MarkerShape
图例标记的默认形状。默认值为 MarkerShapeRectangle。
访问函数
| QLegend::MarkerShape | markerShape() const | 
| void | setMarkerShape(QLegend::MarkerShape shape) | 
通知器信号
| void | markerShapeChanged(QLegend::MarkerShape shape) | 
reverseMarkers : bool
此属性存储是否在图例中使用反向顺序的标记。
默认值是 false。
访问函数
| bool | reverseMarkers() | 
| void | setReverseMarkers(bool reverseMarkers = true) | 
通知器信号
| void | reverseMarkersChanged(bool reverseMarkers) | 
showToolTips : bool
此属性表示文本截断时是否显示工具提示。
默认值是 false。
访问函数
| bool | showToolTips() const | 
| void | setShowToolTips(bool show) | 
通知器信号
| void | showToolTipsChanged(bool showToolTips) | 
成员函数说明
[虚函数 异常] QLegend::~QLegend()
销毁图例对象。图例始终由一个 QChart 拥有,因此应用程序不应调用此函数。
void QLegend::attachToChart()
将图例附加到图表。图表可能会调整图例的布局。
[信号,自6.2以来] void QLegend::attachedToChartChanged(bool attached)
当图例被附加到或从图表中分离时,发出此信号。
此功能从Qt 6.2开始引入。
[信号] void QLegend::backgroundVisibleChanged(bool visible)
当图例背景的可见性变为可见时,发出此信号。
注意:属性backgroundVisible的通知信号。
[信号] void QLegend::borderColorChanged(QColor color)
当图例背景的边框颜色变为颜色时,发出此信号。
注意:属性borderColor的通知信号。
QBrush QLegend::brush() const
返回图例所使用的画笔。
另请参阅:setBrush()。
[信号] void QLegend::colorChanged(QColor color)
当图例背景的颜色变为颜色时,发出此信号。
注意:属性color的通知信号。
void QLegend::detachFromChart()
将图例从图表中分离。图表将不再调整图例的布局。
[信号] void QLegend::fontChanged(QFont font)
当图例标记的字体变为字体时,发出此信号。
注意:属性font的通知信号。
bool QLegend::isAttachedToChart()
如果图例附加到图表,则返回true。
bool QLegend::isBackgroundVisible() const
返回图例背景的可见性。
注意:属性backgroundVisible的获取函数。
[自6.2以来] bool QLegend::isInteractive() const
返回当图例分离时,是否可以使用鼠标拖动或调整大小。
此功能从Qt 6.2开始引入。
另请参阅:QLegend::setInteractive()。
QBrush QLegend::labelBrush() const
返回用于绘制标签的画笔。
另请参阅:setLabelBrush()。
[信号] void QLegend::labelColorChanged(QColor color)
此信号在用于绘制图例标签的画笔颜色更改为color时发出。
注意:属性labelColor的通知信号。
QList<QLegendMarker *> QLegend::markers(QAbstractSeries *series = nullptr) const
返回图例中的标记列表。可以通过指定返回标记的series来过滤列表。
QPen QLegend::pen() const
返回图例使用的画笔。
另请参阅:setPen().
[信号] void QLegend::reverseMarkersChanged(bool reverseMarkers)
当图例中标记的反向顺序被更改为reverseMarkers时发出此信号。
注意:属性reverseMarkers的通知信号。
void QLegend::setBackgroundVisible(bool visible = true)
设置图例背景的可见性为visible。
注意:属性backgroundVisible的设置函数。
另请参阅:isBackgroundVisible().
void QLegend::setBrush(const QBrush &brush)
设置用于绘制图例背景的brush。
另请参阅:brush().
[自 6.2 开始] void QLegend::setInteractive(bool interactive)
当interactive为true且图例已分离时,图例可以通过鼠标拖动以类似窗口的方式移动和调整大小。
通过将图例从边缘拖出,图例将自动附着到图表的边缘。双击已连接的图例可以将其分离。默认值为false。
此功能从Qt 6.2开始引入。
另请参阅:QLegend::isInteractive().
void QLegend::setLabelBrush(const QBrush &brush)
将用于绘制图例标签的画笔设置为brush。
另请参阅:labelBrush().
void QLegend::setPen(const QPen &pen)
设置用于绘制图例边界的pen。
另请参阅:pen().
void QLegend::setShowToolTips(bool show)
当show为true时,如果标签本身显示省略,图例标签将在鼠标悬停时显示工具提示。默认值为false。
注意:属性showToolTips的设置函数。
另请参阅 showToolTips。
bool QLegend::showToolTips() const
返回当图例标签被缩写时是否显示工具提示。
注意: showToolTips 属性的getter函数。
另请参阅 setShowToolTips。
[信号] void QLegend::showToolTipsChanged(bool showToolTips)
当工具提示的可见性更改为 showToolTips 时,将发出此信号。
注意: showToolTips 属性的通知信号。
© 2024 The Qt Company Ltd. 此处包含的文档贡献的版权归其各自所有者。本文档是根据自由软件基金会发布的 GNU自由文档许可证版本1.3 的条款许可的。Qt及相关的标志是The Qt Company Ltd.在芬兰及/或其他国家和地区的商标。所有其他商标均为其各自所有者的财产。