QLegend#

The QLegend class displays the legend of a chart. More

Synopsis#

Functions#

Signals#

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.

../../_images/examples_percentbarchart_legend.png

See also

QChart

class PySide6.QtCharts.QLegend#
PySide6.QtCharts.QLegend.MarkerShape#

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

Constant

Description

QLegend.MarkerShapeDefault

Default shape determined by QLegend is used for the marker. This value is supported only for individual QLegendMarker items.

QLegend.MarkerShapeRectangle

Rectangular markers are used. Marker size is determined by font size.

QLegend.MarkerShapeCircle

Circular markers are used. Marker size is determined by font size.

QLegend.MarkerShapeRotatedRectangle

Rotated rectangle shaped markers are used. Marker size is determined by font size.

QLegend.MarkerShapeTriangle

Triangular markers are used. Marker size is determined by font size.

QLegend.MarkerShapeStar

Star shaped markers are used. Marker size is determined by font size.

QLegend.MarkerShapePentagon

Pentagon shaped markers are used. Marker size is determined by font size.

QLegend.MarkerShapeFromSeries

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. If a lightMarker is specified for a series, the lightMarker will be shown and its size will be determined by the series marker size.

See also

markerShape

PySide6.QtCharts.QLegend.alignment()#
Return type

Alignment

This property holds How the legend is aligned with the chart..

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

PySide6.QtCharts.QLegend.attachToChart()#

Attaches the legend to a chart. The chart may adjust the layout of the legend.

PySide6.QtCharts.QLegend.attachedToChartChanged(attachedToChart)#
Parameters

attachedToChart – bool

PySide6.QtCharts.QLegend.backgroundVisibleChanged(visible)#
Parameters

visible – bool

PySide6.QtCharts.QLegend.borderColor()#
Return type

PySide6.QtGui.QColor

This property holds The line color of the legend..

PySide6.QtCharts.QLegend.borderColorChanged(color)#
Parameters

colorPySide6.QtGui.QColor

PySide6.QtCharts.QLegend.brush()#
Return type

PySide6.QtGui.QBrush

Returns the brush used by the legend.

See also

setBrush()

PySide6.QtCharts.QLegend.color()#
Return type

PySide6.QtGui.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 SolidPattern .

PySide6.QtCharts.QLegend.colorChanged(color)#
Parameters

colorPySide6.QtGui.QColor

PySide6.QtCharts.QLegend.detachFromChart()#

Detaches the legend from the chart. The chart will no longer adjust the layout of the legend.

PySide6.QtCharts.QLegend.fontChanged(font)#
Parameters

fontPySide6.QtGui.QFont

PySide6.QtCharts.QLegend.interactiveChanged(interactive)#
Parameters

interactive – bool

PySide6.QtCharts.QLegend.isAttachedToChart()#
Return type

bool

Returns true, if the legend is attached to a chart.

PySide6.QtCharts.QLegend.isBackgroundVisible()#
Return type

bool

This property holds Whether the legend background is visible..

PySide6.QtCharts.QLegend.isInteractive()#
Return type

bool

Returns whether the legend can be dragged or resized using a mouse when it is detached.

See also

setInteractive()

PySide6.QtCharts.QLegend.labelBrush()#
Return type

PySide6.QtGui.QBrush

Returns the brush used to draw labels.

See also

setLabelBrush()

PySide6.QtCharts.QLegend.labelColor()#
Return type

PySide6.QtGui.QColor

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

PySide6.QtCharts.QLegend.labelColorChanged(color)#
Parameters

colorPySide6.QtGui.QColor

PySide6.QtCharts.QLegend.markerShape()#
Return type

MarkerShape

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

PySide6.QtCharts.QLegend.markerShapeChanged(shape)#
Parameters

shapeMarkerShape

PySide6.QtCharts.QLegend.markers([series=None])#
Parameters

seriesPySide6.QtCharts.QAbstractSeries

Return type

Returns the list of markers in the legend. The list can be filtered by specifying the series for which the markers are returned.

PySide6.QtCharts.QLegend.pen()#
Return type

PySide6.QtGui.QPen

Returns the pen used by the legend.

See also

setPen()

PySide6.QtCharts.QLegend.reverseMarkers()#
Return type

bool

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

This property is false by default.

PySide6.QtCharts.QLegend.reverseMarkersChanged(reverseMarkers)#
Parameters

reverseMarkers – bool

PySide6.QtCharts.QLegend.setAlignment(alignment)#
Parameters

alignmentAlignment

This property holds How the legend is aligned with the chart..

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

PySide6.QtCharts.QLegend.setBackgroundVisible([visible=true])#
Parameters

visible – bool

This property holds Whether the legend background is visible..

PySide6.QtCharts.QLegend.setBorderColor(color)#
Parameters

colorPySide6.QtGui.QColor

This property holds The line color of the legend..

PySide6.QtCharts.QLegend.setBrush(brush)#
Parameters

brushPySide6.QtGui.QBrush

Sets the brush that is used to draw the background of the legend.

See also

brush()

PySide6.QtCharts.QLegend.setColor(color)#
Parameters

colorPySide6.QtGui.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 SolidPattern .

PySide6.QtCharts.QLegend.setInteractive(interactive)#
Parameters

interactive – bool

When interactive is true and the legend is detached, the legend is able to be moved and resized with a mouse in a similar way to a window.

The legend will automatically attach to an edge of the chart by dragging it off of that edge. Double clicking an attached legend will detach it. This is false by default.

See also

isInteractive()

PySide6.QtCharts.QLegend.setLabelBrush(brush)#
Parameters

brushPySide6.QtGui.QBrush

Sets the brush used to draw the legend labels to brush.

See also

labelBrush()

PySide6.QtCharts.QLegend.setLabelColor(color)#
Parameters

colorPySide6.QtGui.QColor

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

PySide6.QtCharts.QLegend.setMarkerShape(shape)#
Parameters

shapeMarkerShape

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

PySide6.QtCharts.QLegend.setPen(pen)#
Parameters

penPySide6.QtGui.QPen

Sets the pen that is used to draw the legend borders.

See also

pen()

PySide6.QtCharts.QLegend.setReverseMarkers([reverseMarkers=true])#
Parameters

reverseMarkers – bool

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

This property is false by default.

PySide6.QtCharts.QLegend.setShowToolTips(show)#
Parameters

show – bool

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

This property is false by default.

PySide6.QtCharts.QLegend.showToolTips()#
Return type

bool

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

This property is false by default.

PySide6.QtCharts.QLegend.showToolTipsChanged(showToolTips)#
Parameters

showToolTips – bool