- Qt 6.12
- Qt Graphs
- C++ Classes
- QtGraphs
- QPieSeries
- Qt Graphs | Commercial or GPLv3

# QPieSeries Class

The QPieSeries class presents data in pie graphs. More...

Header: | `#include <QPieSeries>`
CMake: | `find_package(Qt6 REQUIRED COMPONENTS Graphs)` `target_link_libraries(mytarget PRIVATE Qt6::Graphs)`
qmake: | `QT += graphs`
In QML: | PieSeries
Inherits: | QAbstractSeries

- List of all members, including inherited members
- QPieSeries is part of Qt Graphs C++ Classes for 2D.

## Public Types

`(since 6.10)` enum class | LabelVisibility { None, First, Even, Odd }

## Properties

`(since 6.10)` angleSpanLabelVisibility : LabelVisibility `(since 6.10)` angleSpanVisibleLimit : qreal count : qsizetype endAngle : qreal holeSize : qreal horizontalPosition : qreal | pieSize : qreal `(since 6.12)` sliceData : QList<qreal> `(since 6.12)` sliceLabels : QStringList startAngle : qreal sum : qreal verticalPosition : qreal

## Public Functions

| QPieSeries(QObject *parent = nullptr)
QPieSeries::LabelVisibility | angleSpanLabelVisibility() const
qreal | angleSpanVisibleLimit() const
bool | append(QPieSlice *slice)
bool | append(const QList<QPieSlice *> &slices)
QPieSlice * | append(const QString &label, qreal value)
QPieSlice * | at(qsizetype index)
void | clear()
qsizetype | count() const
qreal | endAngle() const
QPieSlice * | find(const QString &label)
qreal | holeSize() const
qreal | horizontalPosition() const
bool | insert(qsizetype index, QPieSlice *slice)
bool | isEmpty() const
qreal | pieSize() const
bool | remove(QPieSlice *slice)
bool | remove(qsizetype index)
void | removeMultiple(qsizetype index, int count)
bool | replace(const QList<QPieSlice *> &slices)
bool | replace(QPieSlice *oldSlice, QPieSlice *newSlice)
bool | replace(qsizetype index, QPieSlice *slice)
void | setAngleSpanLabelVisibility(QPieSeries::LabelVisibility newAngleSpanVisibleMode)
void | setAngleSpanVisibleLimit(qreal newAngleSpanVisibleLimit)
void | setEndAngle(qreal angle)
void | setHoleSize(qreal holeSize)
void | setHorizontalPosition(qreal relativePosition)
void | setLabelsPosition(QPieSlice::LabelPosition position)
void | setLabelsVisible(bool visible)
void | setPieSize(qreal relativeSize)
void | setSliceData(const QList<qreal> &newSliceData)
void | setSliceLabels(QStringList newLabels)
void | setStartAngle(qreal angle)
void | setVerticalPosition(qreal relativePosition)
QList<qreal> | sliceData() const
const QStringList & | sliceLabels() const &
QStringList | sliceLabels() &&
QList<QPieSlice *> | slices() const
qreal | startAngle() const
qreal | sum() const
bool | take(QPieSlice *slice)
qreal | verticalPosition() const
QPieSeries & | operator<<(QPieSlice *slice)

## Reimplemented Public Functions

virtual QAbstractSeries::SeriesType | type() const override

## Signals

void | added(const QList<QPieSlice *> &slices)
void | angleSpanLabelVisibilityChanged(QPieSeries::LabelVisibility visibility)
void | angleSpanVisibleLimitChanged(qreal limit)
void | countChanged()
void | endAngleChanged()
void | holeSizeChanged()
void | horizontalPositionChanged()
void | pieSizeChanged()
void | removed(const QList<QPieSlice *> &slices)
void | sliceDataChanged(const QList<qreal> &sliceData)
void | sliceLabelsChanged(const QStringList &sliceLabels)
void | startAngleChanged()
void | sumChanged()
void | verticalPositionChanged()

## Detailed Description

A pie series consists of slices that are defined as QPieSlice objects. The slices can have any values as the QPieSeries object calculates the percentage of a slice compared with the sum of all slices in the series to determine the actual size of the slice in the graph.

Pie size and position on the graph are controlled by using relative values that range from 0.0 to 1.0. These relate to the actual graph rectangle.

By default, the pie is defined as a full pie. A partial pie can be created by setting a starting angle and angle span for the series. A full pie is 360 degrees, where 0 is at 12 a'clock.

See also QPieSlice.

## Member Type Documentation

### `[since 6.10]` enum class QPieSeries::LabelVisibility

The mode for label visibility.

Constant | Value | Description
--- | --- | ---
`QPieSeries::LabelVisibility::None` | `0` | All of the labels of slices with smaller angle span than the angleSpanVisibleLimit will be hidden.
`QPieSeries::LabelVisibility::First` | `1` | All except the first label of consecutive slices with smaller angle span than the angleSpanVisibleLimit will be hidden. This is the default value.
`QPieSeries::LabelVisibility::Even` | `2` | Every other label of consecutive slices with smaller angle span than the angleSpanVisibleLimit will be hidden, starting from the second one.
`QPieSeries::LabelVisibility::Odd` | `3` | Every other label of consecutive slices with smaller angle span than the angleSpanVisibleLimit will be hidden, starting from the first one.

This enum was introduced in Qt 6.10.

See also QPieSeries::angleSpanVisibleLimit.

## Property Documentation

### `[since 6.10]` angleSpanLabelVisibility : LabelVisibility

This property holds the mode for label visibility.

The mode which determines which labels will be hidden if they are under the angle span limit set with angleSpanVisibleLimit. Has no effect if angleSpanVisibleLimit has not been set.

This enumeration was introduced in Qt 6.10.

Access functions:

QPieSeries::LabelVisibility | angleSpanLabelVisibility() const
void | setAngleSpanLabelVisibility(QPieSeries::LabelVisibility newAngleSpanVisibleMode)

Notifier signal:

void | angleSpanLabelVisibilityChanged(QPieSeries::LabelVisibility visibility)

See also QPieSeries::angleSpanVisibleLimit.

### `[since 6.10]` angleSpanVisibleLimit : qreal

This property holds the angle span limit for label visibility.

The angle span that will be used as the visibility limit for a slice label. A slice with angle span under this value will change its visibility based on the angleSpanLabelVisibility set to the series. The default value is `0`, which means no slices will be hidden regardless of the angleSpanLabelVisibility.

This enumeration was introduced in Qt 6.10.

Access functions:

qreal | angleSpanVisibleLimit() const
void | setAngleSpanVisibleLimit(qreal newAngleSpanVisibleLimit)

Notifier signal:

void | angleSpanVisibleLimitChanged(qreal limit)

See also QPieSeries::angleSpanLabelVisibility.

### `[read-only]` count : qsizetype

This property holds the number of slices in the series.

Access functions:

qsizetype | count() const

Notifier signal:

void | countChanged()

### endAngle : qreal

This property holds the ending angle of the pie.

A full pie is 360 degrees, where 0 degrees is at 12 o'clock.

The default value is 360.

Access functions:

qreal | endAngle() const
void | setEndAngle(qreal angle)

Notifier signal:

void | endAngleChanged()

### holeSize : qreal

This property holds the donut hole size.

When setting the pieSize property, this property is adjusted if necessary, to ensure that the hole size is not greater than the pie size.

The default value is 0.0.

Access functions:

qreal | holeSize() const
void | setHoleSize(qreal holeSize)

Notifier signal:

void | holeSizeChanged()

### horizontalPosition : qreal

This property holds the horizontal position of the pie.

The value is relative to the graph rectangle, so that:

- 0.0 is the absolute left.
- 1.0 is the absolute right.

The default value is 0.5 (center).

Access functions:

qreal | horizontalPosition() const
void | setHorizontalPosition(qreal relativePosition)

Notifier signal:

void | horizontalPositionChanged()

See also verticalPosition.

### pieSize : qreal

This property holds the pie size.

The value is relative to the graph rectangle, so that:

- 0.0 is the minimum pieSize (pie not drawn).
- 1.0 is the maximum pieSize that can fit the graph.

When setting this property, the holeSize property is adjusted if necessary, to ensure that the hole size is not greater than the pie size.

The default value is 0.7.

Access functions:

qreal | pieSize() const
void | setPieSize(qreal relativeSize)

Notifier signal:

void | pieSizeChanged()

### `[since 6.12]` sliceData : QList<qreal>

Declarative slice values.

Set this property to create pie slices declaratively. The series automatically creates one slice per value. Labels can be supplied via sliceLabels.

Note: Mixing declarative and imperative data input is not supported.

This enumeration was introduced in Qt 6.12.

Access functions:

QList<qreal> | sliceData() const
void | setSliceData(const QList<qreal> &newSliceData)

Notifier signal:

void | sliceDataChanged(const QList<qreal> &sliceData)

See also sliceLabels.

### `[since 6.12]` sliceLabels : QStringList

Declarative slice labels.

Provides labels for slices created via sliceData. Labels must be in the same order as the values. Extra labels beyond the number of slices are ignored.

Note: Mixing declarative and imperative data input is not supported.

This enumeration was introduced in Qt 6.12.

Access functions:

const QStringList & | sliceLabels() const &
QStringList | sliceLabels() &&
void | setSliceLabels(QStringList newLabels)

Notifier signal:

void | sliceLabelsChanged(const QStringList &sliceLabels)

See also sliceData.

### startAngle : qreal

This property holds the starting angle of the pie.

A full pie is 360 degrees, where 0 degrees is at 12 o'clock.

The default value is 0.

Access functions:

qreal | startAngle() const
void | setStartAngle(qreal angle)

Notifier signal:

void | startAngleChanged()

### `[read-only]` sum : qreal

This property holds the sum of all slices.

The series keeps track of the sum of all the slices it holds.

Access functions:

qreal | sum() const

Notifier signal:

void | sumChanged()

### verticalPosition : qreal

This property holds the vertical position of the pie.

The value is relative to the graph rectangle, so that:

- 0.0 is the absolute top.
- 1.0 is the absolute bottom.

The default value is 0.5 (center).

Access functions:

qreal | verticalPosition() const
void | setVerticalPosition(qreal relativePosition)

Notifier signal:

void | verticalPositionChanged()

See also horizontalPosition.

## Member Function Documentation

### `[explicit]` QPieSeries::QPieSeries(QObject *parent = nullptr)

Constructs a series object that is a child of parent.

### `[signal]` void QPieSeries::added(const QList<QPieSlice *> &slices)

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

See also append().

### `[invokable]` bool QPieSeries::append(QPieSlice *slice)

Appends the slice specified by slice to the series. Slice ownership is passed to the series.

Returns `true` if appending succeeds.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

### `[invokable]` bool QPieSeries::append(const QList<QPieSlice *> &slices)

Appends the array of slices specified by slices to the series. Slice ownership is passed to the series.

Returns `true` if appending succeeds.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

### `[invokable]` QPieSlice *QPieSeries::append(const QString &label, qreal value)

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

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

### `[invokable]` QPieSlice *QPieSeries::at(qsizetype index)

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

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

### `[invokable]` void QPieSeries::clear()

Clears all slices from the series.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

### qsizetype QPieSeries::count() const

Returns the number of the slices in this series.

Note: Getter function for property count.

### qreal QPieSeries::endAngle() const

Returns the end angle of the pie.

A full pie is 360 degrees, where 0 degrees is at 12 o'clock.

Note: Getter function for property endAngle.

See also setEndAngle(), startAngle(), and setStartAngle().

### `[invokable]` QPieSlice *QPieSeries::find(const QString &label)

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

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

### `[invokable]` bool QPieSeries::insert(qsizetype index, QPieSlice *slice)

Inserts the slice specified by slice to the series before the slice at the position specified by index. Slice ownership is passed to the series.

Returns `true` if inserting succeeds.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

### bool QPieSeries::isEmpty() const

Returns `true` if the series is empty.

### `[invokable]` bool QPieSeries::remove(QPieSlice *slice)

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

The pointer cannot be referenced after this call.

Returns `true` if the removal succeeds.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

### `[invokable]` bool QPieSeries::remove(qsizetype index)

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

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

### `[invokable]` void QPieSeries::removeMultiple(qsizetype index, int count)

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

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

### `[signal]` void QPieSeries::removed(const QList<QPieSlice *> &slices)

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

See also remove().

### `[invokable]` bool QPieSeries::replace(const QList<QPieSlice *> &slices)

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

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

### `[invokable]` bool QPieSeries::replace(QPieSlice *oldSlice, QPieSlice *newSlice)

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

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

### `[invokable]` bool QPieSeries::replace(qsizetype index, QPieSlice *slice)

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.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

### void QPieSeries::setEndAngle(qreal angle)

Sets the end angle of the pie.

A full pie is 360 degrees, where 0 degrees is at 12 o'clock.

angle must be greater than the start angle.

Note: Setter function for property endAngle.

See also endAngle(), startAngle(), and setStartAngle().

### void QPieSeries::setLabelsPosition(QPieSlice::LabelPosition position)

Sets the position of all the slice labels to position.

Note: This function affects only the current slices in the series. If a new slice is added, the default label position is QPieSlice::LabelOutside.

See also QPieSlice::labelPosition() and QPieSlice::setLabelPosition().

### void QPieSeries::setLabelsVisible(bool visible)

Sets the visibility of all slice labels to visible.

Note: This function affects only the current slices in the series. If a new slice is added, the default label visibility is `false`.

See also QPieSlice::isLabelVisible() and QPieSlice::setLabelVisible().

### void QPieSeries::setStartAngle(qreal angle)

Sets the start angle of the pie.

A full pie is 360 degrees, where 0 degrees is at 12 o'clock.

angle must be smaller than the end angle.

Note: Setter function for property startAngle.

See also startAngle(), endAngle(), and setEndAngle().

### QList<QPieSlice *> QPieSeries::slices() const

Returns a list of slices that belong to this series.

### qreal QPieSeries::startAngle() const

Returns the start angle of the pie.

A full pie is 360 degrees, where 0 degrees is at 12 o'clock.

Note: Getter function for property startAngle.

See also setStartAngle(), endAngle(), and setEndAngle().

### qreal QPieSeries::sum() const

Returns the sum of all slice values in this series.

Note: Getter function for property sum.

See also QPieSlice::value(), QPieSlice::setValue(), and QPieSlice::percentage().

### `[invokable]` bool QPieSeries::take(QPieSlice *slice)

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

Note: The series remains the slice's parent object. You must set the parent object to take full ownership.

Returns `true` if the take operation was successful.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

### `[override virtual]` QAbstractSeries::SeriesType QPieSeries::type() const

Reimplements an access function for property: QAbstractSeries::type.

Returns the type of the series.

### QPieSeries &QPieSeries::operator<<(QPieSlice *slice)

Appends the slice specified by slice to the series and returns a reference to the series. Slice ownership is passed to the series.