QPieSlice Class
The QPieSlice class is one slice of a pie series. More…
| Header | #include <QPieSlice> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Charts) |
| Module | Nt Charts C++ Classes |
| Inherits | QObject |
List of all members, including inherited members
Public Types
| enum | LabelPosition |
Public Functions
| QPieSlice(QObject *parent = nullptr) | |
| QPieSlice(const QString &label, qreal value, QObject *parent = nullptr) | |
| ~QPieSlice() | |
| void | setLabel(const QString &label) |
| QString | label() const |
| void | setValue(qreal value) |
| qreal | value() const |
| void | setLabelVisible(bool visible = true) |
| bool | isLabelVisible() const |
| LabelPosition | labelPosition() |
| void | setLabelPosition(LabelPosition position) |
| void | setExploded(bool exploded = true) |
| bool | isExploded() const |
| void | setPen(const QPen &pen) |
| QPen | pen() const |
| QColor | borderColor() |
| void | setBorderColor(QColor color) |
| int | borderWidth() |
| void | setBorderWidth(int width) |
| void | setBrush(const QBrush &brush) |
| QBrush | brush() const |
| QColor | color() |
| void | setColor(QColor color) |
| void | setLabelBrush(const QBrush &brush) |
| QBrush | labelBrush() const |
| QColor | labelColor() |
| void | setLabelColor(QColor color) |
| void | setLabelFont(const QFont &font) |
| QFont | labelFont() const |
| void | setLabelArmLengthFactor(qreal factor) |
| qreal | labelArmLengthFactor() const |
| void | setExplodeDistanceFactor(qreal factor) |
| qreal | explodeDistanceFactor() const |
| qreal | percentage() const |
| qreal | startAngle() const |
| qreal | angleSpan() const |
| QPieSeries * | series() const |
Signals
| void | clicked() |
| void | hovered(bool state) |
| void | pressed() |
| void | released() |
| void | doubleClicked() |
| void | labelChanged() |
| void | valueChanged() |
| void | labelVisibleChanged() |
| void | penChanged() |
| void | brushChanged() |
| void | labelBrushChanged() |
| void | labelFontChanged() |
| void | percentageChanged() |
| void | startAngleChanged() |
| void | angleSpanChanged() |
| void | colorChanged() |
| void | borderColorChanged() |
| void | borderWidthChanged() |
| void | labelColorChanged() |
Detailed Description

A slice has a value and a label. Its share of the pie, percentage(), is its value divided by the sum of the values of the series. A slice can be exploded, moved out of the pie, and its label can be shown outside the pie, joined to it by an arm, or inside it.
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);
See also QPieSeries.
Differences from Qt
The label is drawn upright for every LabelPosition: LabelInsideTangential and LabelInsideNormal are drawn as LabelInsideHorizontal. Slices are filled with the color of their brush only.
Member Type Documentation
enum QPieSlice::LabelPosition
Where the label of a slice is drawn.
| Constant | Description |
|---|---|
QPieSlice::LabelOutside | Outside the pie, joined to the slice by an arm. |
QPieSlice::LabelInsideHorizontal | Inside the slice, horizontally. |
QPieSlice::LabelInsideTangential | Inside the slice, along the circle; Nt draws it horizontally. |
QPieSlice::LabelInsideNormal | Inside the slice, along the radius; Nt draws it horizontally. |
Member Function Documentation
QPieSlice::QPieSlice(QObject *parent = nullptr)
Constructs a slice with no label and a value of 0, with the given parent.
QPieSlice::QPieSlice(const QString &label, qreal value, QObject *parent = nullptr)
Constructs a slice called label with the value value, with the given parent.
QPieSlice::~QPieSlice()
Destroys the slice and removes it from its series.
qreal QPieSlice::angleSpan() const
Returns the angle the slice spans, in degrees.
void QPieSlice::angleSpanChanged()
This signal is emitted when the angle that the slice spans changes.
QColor QPieSlice::borderColor()
Returns the color of the border.
void QPieSlice::borderColorChanged()
This signal is emitted when the border color changes.
int QPieSlice::borderWidth()
Returns the width of the border in pixels.
void QPieSlice::borderWidthChanged()
This signal is emitted when the border width changes.
QBrush QPieSlice::brush() const
Returns the brush of the slice. Unless one was set, it has the color the theme gives the slice.
void QPieSlice::brushChanged()
This signal is emitted when the brush changes.
void QPieSlice::clicked()
This signal is emitted when the user clicks the slice.
QColor QPieSlice::color()
Returns the fill color of the slice.
void QPieSlice::colorChanged()
This signal is emitted when the fill color changes.
void QPieSlice::doubleClicked()
This signal is emitted when the user double-clicks the slice.
qreal QPieSlice::explodeDistanceFactor() const
Returns how far an exploded slice moves out, as a factor of the radius of the pie.
void QPieSlice::hovered(bool state)
This signal is emitted when the mouse enters or leaves the slice; state is true when it enters.
bool QPieSlice::isExploded() const
Returns true if the slice is moved out of the pie; otherwise returns false.
bool QPieSlice::isLabelVisible() const
Returns true if the label is drawn; otherwise returns false.
QString QPieSlice::label() const
Returns the label of the slice.
qreal QPieSlice::labelArmLengthFactor() const
Returns the length of the arm of an outside label, as a factor of the radius of the pie.
QBrush QPieSlice::labelBrush() const
Returns the brush of the label.
void QPieSlice::labelBrushChanged()
This signal is emitted when the brush of the label changes.
void QPieSlice::labelChanged()
This signal is emitted when the label changes.
QColor QPieSlice::labelColor()
Returns the color of the label.
void QPieSlice::labelColorChanged()
This signal is emitted when the color of the label changes.
QFont QPieSlice::labelFont() const
Returns the font of the label.
void QPieSlice::labelFontChanged()
This signal is emitted when the font of the label changes.
LabelPosition QPieSlice::labelPosition()
Returns where the label is drawn. The default is LabelOutside.
void QPieSlice::labelVisibleChanged()
This signal is emitted when the label is shown or hidden.
QPen QPieSlice::pen() const
Returns the pen of the border of the slice. Unless one was set, it has the background color of the chart and is 2 pixels wide, which separates the slices.
void QPieSlice::penChanged()
This signal is emitted when the pen changes.
qreal QPieSlice::percentage() const
Returns the share of the slice in its series, from 0.0 to 1.0.
void QPieSlice::percentageChanged()
This signal is emitted when the share of the slice in the series changes.
void QPieSlice::pressed()
This signal is emitted when the user presses a mouse button on the slice.
void QPieSlice::released()
This signal is emitted when the user releases a mouse button on the slice.
QPieSeries * QPieSlice::series() const
Returns the series the slice is in, or nullptr if it is in none.
void QPieSlice::setBorderColor(QColor color)
Sets the color of the border to color.
void QPieSlice::setBorderWidth(int width)
Sets the width of the border to width pixels.
void QPieSlice::setBrush(const QBrush &brush)
Sets the brush of the slice to brush.
void QPieSlice::setColor(QColor color)
Sets the fill color of the slice to color.
void QPieSlice::setExploded(bool exploded = true)
Moves the slice out of the pie if exploded is true.
See also setExplodeDistanceFactor().
void QPieSlice::setExplodeDistanceFactor(qreal factor)
Sets how far an exploded slice moves out to factor times the radius of the pie. The default is 0.15.
void QPieSlice::setLabel(const QString &label)
Sets the label of the slice to label.
void QPieSlice::setLabelArmLengthFactor(qreal factor)
Sets the length of the arm of an outside label to factor times the radius of the pie. The default is 0.15.
void QPieSlice::setLabelBrush(const QBrush &brush)
Sets the brush of the label to brush.
void QPieSlice::setLabelColor(QColor color)
Sets the color of the label to color.
void QPieSlice::setLabelFont(const QFont &font)
Sets the font of the label to font.
void QPieSlice::setLabelPosition(LabelPosition position)
Sets where the label is drawn to position.
void QPieSlice::setLabelVisible(bool visible = true)
Shows the label of the slice if visible is true.
void QPieSlice::setPen(const QPen &pen)
Sets the pen of the border of the slice to pen.
void QPieSlice::setValue(qreal value)
Sets the value of the slice to value. Negative values count as zero.
qreal QPieSlice::startAngle() const
Returns the angle at which the slice starts, in degrees clockwise from 12 o'clock.
void QPieSlice::startAngleChanged()
This signal is emitted when the angle at which the slice starts changes.
qreal QPieSlice::value() const
Returns the value of the slice.
void QPieSlice::valueChanged()
This signal is emitted when the value changes.