PySide6.QtGraphs.QPieSlice

class QPieSlice

The QPieSlice class represents a single slice in a pie series.

Details

A pie slice has a value and a label. When the slice is added to a pie series, the QPieSeries object calculates the percentage of the slice compared with the sum of all slices in the series to determine the actual size of the slice in the graph.

By default, the label is hidden. If it is visible, it can be either located outside the slice and connected to it with an arm or centered inside the slice either horizontally or in parallel with the tangential or normal of the slice’s arc.

By default, the visual appearance of the slice is set by a theme, but the theme can be overridden by specifying slice properties. However, if the theme is changed after the slices are customized, all customization will be lost.

To enable user interaction with the pie graph, some basic signals are emitted when users click pie slices or hover the mouse over them.

A pie slice can contain sub slices.

See also

QPieSeries

Inheritance diagram of PySide6.QtGraphs.QPieSlice

Added in version 6.8.

Synopsis

Properties

  • angleSpanᅟ - Span of the slice in degrees. A full pie is 360 degrees, where 0 degrees is at 12 a’clock. Updated automatically once the slice is added to the series

  • borderColorᅟ - Color used to draw the slice border. This is a convenience property for modifying the slice

  • borderWidthᅟ - Width of the slice border. This is a convenience property for modifying the slice border width

  • colorᅟ - Fill color of the slice. This is a convenience property for modifying the slice fill color

  • explodeDistanceFactorᅟ - Determines how far away from the pie the slice is exploded

  • explodedᅟ - Whether the slice is separated from the pie

  • labelᅟ - Of the slice

  • labelArmLengthFactorᅟ - Length of the label arm. The factor is relative to the pie radius. For example:

  • labelColorᅟ - Color used to draw the slice label

  • labelFontᅟ - Font used for drawing the label text

  • labelPositionᅟ - Position of the slice label

  • labelVisibleᅟ - Visibility of the slice label. By default, the label is not visible

  • percentageᅟ - Of the slice compared to the sum of all slices in the series. The actual value ranges from 0.0 to 1.0. Updated automatically once the slice is added to the series

  • startAngleᅟ - Starting angle of this slice in the series it belongs to. A full pie is 360 degrees, where 0 degrees is at 12 a’clock. Updated automatically once the slice is added to the series

  • subSlicesCountᅟ - Number of sub slices in the slice

  • subSlicesRatioᅟ

  • subSlicesSumᅟ - Sum of all sub slices

  • valueᅟ - Of the slice

Methods

Signals

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

class LabelPosition

This enum describes the position of the slice label.

Constant

Description

QPieSlice.LabelPosition.LabelPosition.Outside

The label is located outside the slice connected to it with an arm. This is the default value.

QPieSlice.LabelPosition.LabelPosition.InsideHorizontal

The label is centered within the slice and laid out horizontally.

QPieSlice.LabelPosition.LabelPosition.InsideTangential

The label is centered within the slice and rotated to be parallel with the tangential of the slice’s arc.

QPieSlice.LabelPosition.LabelPosition.InsideNormal

The label is centered within the slice and rotated to be parallel with the normal of the slice’s arc.

Note

Properties can be used directly when from __feature__ import true_property is used or via accessor functions otherwise.

property angleSpanᅟ: float

This property holds The span of the slice in degrees. A full pie is 360 degrees, where 0 degrees is at 12 a’clock. Updated automatically once the slice is added to the series..

Access functions:
property borderColorᅟ: QColor

This property holds The color used to draw the slice border. This is a convenience property for modifying the slice..

See also

borderWidth

Access functions:
property borderWidthᅟ: float

This property holds The width of the slice border. This is a convenience property for modifying the slice border width..

See also

borderColor

Access functions:
property colorᅟ: QColor

This property holds The fill color of the slice. This is a convenience property for modifying the slice fill color..

Access functions:
property explodeDistanceFactorᅟ: float

This property Determines how far away from the pie the slice is exploded..

  • 1.0 means that the distance is the same as the radius.

  • 0.5 means that the distance is half of the radius.

By default, the distance is 0.15

See also

exploded

Access functions:
property explodedᅟ: bool

This property holds Whether the slice is separated from the pie..

Access functions:
property labelᅟ: str

This property holds The label of the slice..

Note

The string can be HTML formatted.

See also

labelVisible labelFont labelArmLengthFactor

Access functions:
property labelArmLengthFactorᅟ: float

This property holds The length of the label arm. The factor is relative to the pie radius. For example:.

  • 1.0 means that the length is the same as the radius.

  • 0.5 means that the length is half of the radius.

By default, the arm length is 0.15

See also

label labelVisible labelFont

Access functions:
property labelColorᅟ: QColor

This property holds The color used to draw the slice label..

Access functions:
property labelFontᅟ: QFont

This property holds The font used for drawing the label text..

See also

label labelVisible labelArmLengthFactor

Access functions:
property labelPositionᅟ: QPieSlice.LabelPosition

This property holds The position of the slice label..

See also

label labelVisible

Access functions:
property labelVisibleᅟ: bool

This property holds The visibility of the slice label. By default, the label is not visible..

Access functions:
property percentageᅟ: float

This property holds The percentage of the slice compared to the sum of all slices in the series. The actual value ranges from 0.0 to 1.0. Updated automatically once the slice is added to the series..

See also

value sum

Access functions:
property startAngleᅟ: float

This property holds The starting angle of this slice in the series it belongs to. A full pie is 360 degrees, where 0 degrees is at 12 a’clock. Updated automatically once the slice is added to the series..

Access functions:
property subSlicesCountᅟ: int

This property holds The number of sub slices in the slice..

Access functions:
property subSlicesRatioᅟ: float

The relative size of the sub slices compared to the parent slice. The value ranges from 0.0 to 1.0, where 1.0 means that the sub slices take up the same amount of space as the parent slice would without sub slices. The default value is 0.6.

Access functions:
property subSlicesSumᅟ: float

This property holds The sum of all sub slices..

The slice keeps track of the sum of all the sub slices it holds.

Access functions:
property valueᅟ: float

This property holds The value of the slice..

Note

A negative value is converted to a positive value.

See also

percentage() sum()

Access functions:
__init__([parent=None])
Parameters:

parentQObject

Constructs an empty slice with the parent parent.

See also

append() insert()

__init__(label, value[, parent=None])
Parameters:
  • label – str

  • value – float

  • parentQObject

Constructs an empty slice with the specified value, label, and parent.

See also

append() insert()

angleSpan()
Return type:

float

Getter of property angleSpanᅟ .

angleSpanChanged()

Notification signal of property angleSpanᅟ .

append(slice)
Parameters:

sliceQPieSlice

Return type:

bool

Appends the sub slice specified by slice to the slice. Sub slice ownership is passed to the slice.

Returns true if appending succeeds.

append(slices)
Parameters:

slices – .list of QPieSlice

Return type:

bool

Appends the array of sub slices specified by slices to the slice. Sub slice ownership is passed to the slice.

Returns true if appending succeeds.

append(label, value)
Parameters:
  • label – str

  • value – float

Return type:

QPieSlice

Appends a single sub slice with the specified value and label to the slice. Sub slice ownership is passed to the slice. Returns null if value is NaN, Inf, or -Inf and adds nothing to the series.

at(index)
Parameters:

index – int

Return type:

QPieSlice

Returns the PieSlice at the position index. Returns null if no PieSlice was found.

borderColor()
Return type:

QColor

See also

setBorderColor()

Getter of property borderColorᅟ .

borderColorChanged()

Notification signal of property borderColorᅟ .

borderWidth()
Return type:

float

See also

setBorderWidth()

Getter of property borderWidthᅟ .

borderWidthChanged()

Notification signal of property borderWidthᅟ .

clear()

Clears all sub slices from the slice.

color()
Return type:

QColor

See also

setColor()

Getter of property colorᅟ .

colorChanged()

Notification signal of property colorᅟ .

explodeDistanceFactor()
Return type:

float

Getter of property explodeDistanceFactorᅟ .

explodeDistanceFactorChanged()

Notification signal of property explodeDistanceFactorᅟ .

explodedChanged()

Notification signal of property explodedᅟ .

find(label)
Parameters:

label – str

Return type:

QPieSlice

Searches for a PieSlice which contains the label label. Returns the PieSlice if found, null otherwise.

insert(index, slice)
Parameters:
Return type:

bool

Inserts the sub slice specified by slice to the slice before the sub slice at the position specified by index. Sub slice ownership is passed to the slice.

Returns true if inserting succeeds.

isEmpty()
Return type:

bool

Returns true if the sub slices list is empty.

isExploded()
Return type:

bool

Getter of property explodedᅟ .

isLabelVisible()
Return type:

bool

Getter of property labelVisibleᅟ .

label()
Return type:

str

See also

setLabel()

Getter of property labelᅟ .

labelArmLengthFactor()
Return type:

float

Getter of property labelArmLengthFactorᅟ .

labelArmLengthFactorChanged()

Notification signal of property labelArmLengthFactorᅟ .

labelChanged()

Notification signal of property labelᅟ .

labelColor()
Return type:

QColor

See also

setLabelColor()

Getter of property labelColorᅟ .

labelColorChanged()

Notification signal of property labelColorᅟ .

labelFont()
Return type:

QFont

See also

setLabelFont()

Getter of property labelFontᅟ .

labelFontChanged()

Notification signal of property labelFontᅟ .

labelPosition()
Return type:

LabelPosition

Getter of property labelPositionᅟ .

labelPositionChanged()

Notification signal of property labelPositionᅟ .

labelVisibleChanged()

Notification signal of property labelVisibleᅟ .

percentage()
Return type:

float

Getter of property percentageᅟ .

percentageChanged()

Notification signal of property percentageᅟ .

remove(slice)
Parameters:

sliceQPieSlice

Return type:

bool

Removes a single sub slice, specified by slice, from the slice and deletes it permanently.

The pointer cannot be referenced after this call.

Returns true if the removal succeeds.

remove(index)
Parameters:

index – int

Return type:

bool

Removes the PieSlice at the location index. The PieSlice will be permanently deleted. Returns true if removing is successful.

removeMultiple(index, count)
Parameters:
  • index – int

  • count – int

Removes multiple PieSlices from the slice starting from index to a number of count. The PieSlices will be permanently deleted.

replace(oldSlice, newSlice)
Parameters:
Return type:

bool

Replaces the PieSlice oldSlice with newSlice if found in the slice. oldSlice will be permanently deleted. Returns true if replacing is successful.

replace(index, slice)
Parameters:
Return type:

bool

Replaces the PieSlice at position index with the one specified by slice. The original PieSlice will be permanently deleted. Returns false if replacing any of the PieSlices fails.

replaceAll(slices)
Parameters:

slices – .list of QPieSlice

Return type:

bool

Replaces the entire list of PieSlices in the slice with the list specified by slices. All the original PieSlices will be permanently deleted. Returns true if all PieSlices are replaced successfully.

series()
Return type:

QPieSeries

Returns the series that this slice belongs to.

See also

append()

setBorderColor(color)
Parameters:

colorQColor

See also

borderColor()

Setter of property borderColorᅟ .

setBorderWidth(borderWidth)
Parameters:

borderWidth – float

See also

borderWidth()

Setter of property borderWidthᅟ .

setColor(color)
Parameters:

colorQColor

See also

color()

Setter of property colorᅟ .

setExplodeDistanceFactor(factor)
Parameters:

factor – float

Setter of property explodeDistanceFactorᅟ .

setExploded(exploded)
Parameters:

exploded – bool

See also

isExploded()

Setter of property explodedᅟ .

setLabel(label)
Parameters:

label – str

See also

label()

Setter of property labelᅟ .

setLabelArmLengthFactor(factor)
Parameters:

factor – float

Setter of property labelArmLengthFactorᅟ .

setLabelColor(color)
Parameters:

colorQColor

See also

labelColor()

Setter of property labelColorᅟ .

setLabelFont(font)
Parameters:

fontQFont

See also

labelFont()

Setter of property labelFontᅟ .

setLabelPosition(position)
Parameters:

positionLabelPosition

See also

labelPosition()

Setter of property labelPositionᅟ .

setLabelVisible([visible=true])
Parameters:

visible – bool

See also

isLabelVisible()

Setter of property labelVisibleᅟ .

setSubSlicesRatio(subSlicesRatio)
Parameters:

subSlicesRatio – float

See also

subSlicesRatio()

Setter of property subSlicesRatioᅟ .

setValue(value)
Parameters:

value – float

See also

value()

Setter of property valueᅟ .

sliceChanged()
startAngle()
Return type:

float

Getter of property startAngleᅟ .

startAngleChanged()

Notification signal of property startAngleᅟ .

subSlices()
Return type:

.list of QPieSlice

Returns a list of sub slices that belong to this slice.

subSlicesAdded(slices)
Parameters:

slices – .list of QPieSlice

This signal is emitted when the sub slices specified by slices are added to the slice.

See also

append()

subSlicesCount()
Return type:

int

Returns the number of the sub slices in this slice.

Getter of property subSlicesCountᅟ .

subSlicesCountChanged(count)
Parameters:

count – int

Notification signal of property subSlicesCountᅟ .

subSlicesRatio()
Return type:

float

Getter of property subSlicesRatioᅟ .

subSlicesRatioChanged(newSubSlicesRatio)
Parameters:

newSubSlicesRatio – float

Notification signal of property subSlicesRatioᅟ .

subSlicesRemoved(slices)
Parameters:

slices – .list of QPieSlice

This signal is emitted when the sub slices specified by slices are removed from the slice.

See also

remove()

subSlicesReplaced(slices)
Parameters:

slices – .list of QPieSlice

subSlicesSum()
Return type:

float

Returns the sum of all sub slices values in this slice.

Getter of property subSlicesSumᅟ .

subSlicesSumChanged(sum)
Parameters:

sum – float

Notification signal of property subSlicesSumᅟ .

take(slice)
Parameters:

sliceQPieSlice

Return type:

bool

Takes a single sub slice, specified by slice, from the series. Does not delete the slice object.

Note

The slice remains the slice’s parent object. You must set the parent object to take full ownership.

Returns true if the take operation was successful.

value()
Return type:

float

See also

setValue()

Getter of property valueᅟ .

valueChanged()

Notification signal of property valueᅟ .