6.0.0-rc4Source

QPieSlice Class

The QPieSlice class is one slice of a pie series. More…

Header#include <QPieSlice>
CMaketarget_link_libraries(app PRIVATE Nt::Charts)
ModuleNt Charts C++ Classes
InheritsQObject

List of all members, including inherited members

Public Types

Public Functions

QPieSlice(QObject *parent = nullptr)
QPieSlice(const QString &label, qreal value, QObject *parent = nullptr)
~QPieSlice()
voidsetLabel(const QString &label)
QStringlabel() const
voidsetValue(qreal value)
qrealvalue() const
voidsetLabelVisible(bool visible = true)
boolisLabelVisible() const
LabelPositionlabelPosition()
voidsetLabelPosition(LabelPosition position)
voidsetExploded(bool exploded = true)
boolisExploded() const
voidsetPen(const QPen &pen)
QPenpen() const
QColorborderColor()
voidsetBorderColor(QColor color)
intborderWidth()
voidsetBorderWidth(int width)
voidsetBrush(const QBrush &brush)
QBrushbrush() const
QColorcolor()
voidsetColor(QColor color)
voidsetLabelBrush(const QBrush &brush)
QBrushlabelBrush() const
QColorlabelColor()
voidsetLabelColor(QColor color)
voidsetLabelFont(const QFont &font)
QFontlabelFont() const
voidsetLabelArmLengthFactor(qreal factor)
qreallabelArmLengthFactor() const
voidsetExplodeDistanceFactor(qreal factor)
qrealexplodeDistanceFactor() const
qrealpercentage() const
qrealstartAngle() const
qrealangleSpan() const
QPieSeries *series() const

Signals

Detailed Description

Slices with outside labels; the Free slice is exploded

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.

ConstantDescription
QPieSlice::LabelOutsideOutside the pie, joined to the slice by an arm.
QPieSlice::LabelInsideHorizontalInside the slice, horizontally.
QPieSlice::LabelInsideTangentialInside the slice, along the circle; Nt draws it horizontally.
QPieSlice::LabelInsideNormalInside the slice, along the radius; Nt draws it horizontally.

Member Function Documentation

[explicit] 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.

[override] QPieSlice::~QPieSlice()

Destroys the slice and removes it from its series.

qreal QPieSlice::angleSpan() const

Returns the angle the slice spans, in degrees.

[signal] void QPieSlice::angleSpanChanged()

This signal is emitted when the angle that the slice spans changes.

QColor QPieSlice::borderColor()

Returns the color of the border.

[signal] void QPieSlice::borderColorChanged()

This signal is emitted when the border color changes.

int QPieSlice::borderWidth()

Returns the width of the border in pixels.

[signal] 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.

[signal] void QPieSlice::brushChanged()

This signal is emitted when the brush changes.

[signal] void QPieSlice::clicked()

This signal is emitted when the user clicks the slice.

QColor QPieSlice::color()

Returns the fill color of the slice.

[signal] void QPieSlice::colorChanged()

This signal is emitted when the fill color changes.

[signal] 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.

[signal] 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.

[signal] void QPieSlice::labelBrushChanged()

This signal is emitted when the brush of the label changes.

[signal] void QPieSlice::labelChanged()

This signal is emitted when the label changes.

QColor QPieSlice::labelColor()

Returns the color of the label.

[signal] void QPieSlice::labelColorChanged()

This signal is emitted when the color of the label changes.

QFont QPieSlice::labelFont() const

Returns the font of the label.

[signal] 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.

[signal] 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.

[signal] 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.

[signal] void QPieSlice::percentageChanged()

This signal is emitted when the share of the slice in the series changes.

[signal] void QPieSlice::pressed()

This signal is emitted when the user presses a mouse button on the slice.

[signal] 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.

[signal] 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.

[signal] void QPieSlice::valueChanged()

This signal is emitted when the value changes.