QPieSeries Class
The QPieSeries class draws its slices as a pie or a donut. More…
| Header | #include <QPieSeries> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Charts) |
| Module | Nt Charts C++ Classes |
| Inherits | QAbstractSeries |
List of all members, including inherited members
Public Functions
| QPieSeries(QObject *parent = nullptr) | |
| ~QPieSeries() | |
| bool | append(QPieSlice *slice) |
| bool | append(const QList<QPieSlice *> &slices) |
| QPieSeries & | operator<<(QPieSlice *slice) |
| QPieSlice * | append(const QString &label, qreal value) |
| bool | insert(int index, QPieSlice *slice) |
| bool | remove(QPieSlice *slice) |
| bool | take(QPieSlice *slice) |
| void | clear() |
| QList<QPieSlice *> | slices() const |
| int | count() const |
| bool | isEmpty() const |
| qreal | sum() const |
| void | setHoleSize(qreal holeSize) |
| qreal | holeSize() const |
| void | setHorizontalPosition(qreal relativePosition) |
| qreal | horizontalPosition() const |
| void | setVerticalPosition(qreal relativePosition) |
| qreal | verticalPosition() const |
| void | setPieSize(qreal relativeSize) |
| qreal | pieSize() const |
| void | setPieStartAngle(qreal startAngle) |
| qreal | pieStartAngle() const |
| void | setPieEndAngle(qreal endAngle) |
| qreal | pieEndAngle() const |
| void | setLabelsVisible(bool visible = true) |
| void | setLabelsPosition(QPieSlice::LabelPosition position) |
Reimplemented Public Functions
| QAbstractSeries::SeriesType | type() const |
Signals
| void | added(const QList<QPieSlice *> &slices) |
| void | removed(const QList<QPieSlice *> &slices) |
| void | clicked(QPieSlice *slice) |
| void | hovered(QPieSlice *slice, bool state) |
| void | pressed(QPieSlice *slice) |
| void | released(QPieSlice *slice) |
| void | doubleClicked(QPieSlice *slice) |
| void | countChanged() |
| void | sumChanged() |
Detailed Description

Each QPieSlice takes a share of the circle in proportion to its value. setHoleSize() makes the pie a donut, and setPieStartAngle() and setPieEndAngle() draw part of a circle, such as a half-circle gauge. The series owns its slices.
auto *series = new QPieSeries;
series->setHoleSize(0.4);
series->append("Passed", 182);
series->append("Skipped", 11);
QPieSlice *failed = series->append("Failed", 7);
failed->setExploded(true);
failed->setLabelVisible(true);
QObject::connect(series, &QPieSeries::hovered, [](QPieSlice *slice, bool state) { slice->setExploded(state); });
auto *chart = new QChart;
chart->setTitle("Tests");
chart->addSeries(series);
chart->legend()->setAlignment(Qt::AlignRight);

A pie series has no axes. The pie is centered at horizontalPosition() and verticalPosition() of the plot area, and its diameter is pieSize() times the smaller side of the plot area. Outside labels must fit in the plot area, so the pie is made smaller when they need the room.
See also QPieSlice.
Differences from Qt
There is no QPieModelMapper. See QPieSlice for the labels.
Member Function Documentation
QPieSeries::QPieSeries(QObject *parent = nullptr)
Constructs an empty pie series with the given parent.
QPieSeries::~QPieSeries()
Destroys the series and its slices.
void QPieSeries::added(const QList<QPieSlice *> &slices)
This signal is emitted when slices are added to the series.
bool QPieSeries::append(QPieSlice *slice)
Appends slice to the series, which takes ownership of it. Returns false if slice is nullptr or already in a series.
bool QPieSeries::append(const QList<QPieSlice *> &slices)
This is an overloaded function.
Appends slices. Returns false, and appends none of them, if one of them is nullptr, appears twice or is already in a series.
QPieSlice * QPieSeries::append(const QString &label, qreal value)
This is an overloaded function.
Appends a new slice called label with the value value, and returns it.
void QPieSeries::clear()
Removes and deletes all slices.
void QPieSeries::clicked(QPieSlice *slice)
This signal is emitted when the user clicks slice.
int QPieSeries::count() const
Returns the number of slices.
void QPieSeries::countChanged()
This signal is emitted when the number of slices changes.
void QPieSeries::doubleClicked(QPieSlice *slice)
This signal is emitted when the user double-clicks slice.
qreal QPieSeries::holeSize() const
Returns the diameter of the hole, as a share of the smaller side of the plot area.
qreal QPieSeries::horizontalPosition() const
Returns the horizontal position of the center, from 0.0 to 1.0.
void QPieSeries::hovered(QPieSlice *slice, bool state)
This signal is emitted when the mouse enters or leaves slice; state is true when it enters.
bool QPieSeries::insert(int index, QPieSlice *slice)
Inserts slice at index; an index out of range appends it. Returns false if slice is nullptr or already in a series.
bool QPieSeries::isEmpty() const
Returns true if the series has no slices; otherwise returns false.
QPieSeries & QPieSeries::operator<<(QPieSlice *slice)
Appends slice and returns a reference to the series.
qreal QPieSeries::pieEndAngle() const
Returns the angle at which the last slice ends.
qreal QPieSeries::pieSize() const
Returns the diameter of the pie, as a share of the smaller side of the plot area.
qreal QPieSeries::pieStartAngle() const
Returns the angle at which the first slice starts.
void QPieSeries::pressed(QPieSlice *slice)
This signal is emitted when the user presses a mouse button on slice.
void QPieSeries::released(QPieSlice *slice)
This signal is emitted when the user releases a mouse button on slice.
bool QPieSeries::remove(QPieSlice *slice)
Removes slice from the series and deletes it. Returns true on success.
void QPieSeries::removed(const QList<QPieSlice *> &slices)
This signal is emitted when slices are removed from the series.
void QPieSeries::setHoleSize(qreal holeSize)
Sets the diameter of the hole in the middle to holeSize, as a share of the smaller side of the plot area, from 0.0 (a pie) to pieSize() (nothing left).
void QPieSeries::setHorizontalPosition(qreal relativePosition)
Sets the horizontal position of the center to relativePosition, from 0.0 (left edge of the plot area) to 1.0 (right edge). The default is 0.5.
void QPieSeries::setLabelsPosition(QPieSlice::LabelPosition position)
Sets where the labels of all slices are drawn to position.
void QPieSeries::setLabelsVisible(bool visible = true)
Shows the labels of all slices if visible is true, and hides them otherwise.
void QPieSeries::setPieEndAngle(qreal endAngle)
Sets the angle at which the last slice ends to endAngle degrees, clockwise from 12 o'clock. The default is 360.
void QPieSeries::setPieSize(qreal relativeSize)
Sets the diameter of the pie to relativeSize, as a share of the smaller side of the plot area, from 0.0 to 1.0. The default is 0.7.
void QPieSeries::setPieStartAngle(qreal startAngle)
Sets the angle at which the first slice starts to startAngle degrees, clockwise from 12 o'clock. The default is 0.
void QPieSeries::setVerticalPosition(qreal relativePosition)
Sets the vertical position of the center to relativePosition, from 0.0 (top edge of the plot area) to 1.0 (bottom edge). The default is 0.5.
QList<QPieSlice *> QPieSeries::slices() const
Returns the slices.
qreal QPieSeries::sum() const
Returns the sum of the values of the slices; negative values count as zero.
void QPieSeries::sumChanged()
This signal is emitted when the sum of the values changes.
bool QPieSeries::take(QPieSlice *slice)
Removes slice from the series without deleting it; the caller owns it. Returns true on success.
QAbstractSeries::SeriesType QPieSeries::type() const
Reimplements QAbstractSeries::type().
Returns QAbstractSeries::SeriesTypePie.
qreal QPieSeries::verticalPosition() const
Returns the vertical position of the center, from 0.0 to 1.0.