The QPieSlice class represents a single slice in a pie series. More...
| Header: | #include <QPieSlice> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Graphs)target_link_libraries(mytarget PRIVATE Qt6::Graphs) |
| qmake: | QT += graphs |
| In QML: | PieSlice |
| Inherits: | QObject |
| enum class | LabelPosition { Outside, InsideHorizontal, InsideTangential, InsideNormal } |
|
|
| QPieSlice(QObject *parent = nullptr) | |
| QPieSlice(const QString &label, qreal value, QObject *parent = nullptr) | |
| virtual | ~QPieSlice() override |
| qreal | angleSpan() const |
| QColor | borderColor() const |
| qreal | borderWidth() const |
| QColor | color() const |
| qreal | explodeDistanceFactor() const |
| bool | isExploded() const |
| bool | isLabelVisible() const |
| QString | label() const |
| qreal | labelArmLengthFactor() const |
| QColor | labelColor() const |
| QFont | labelFont() const |
| QPieSlice::LabelPosition | labelPosition() |
| qreal | percentage() const |
| QPieSeries * | series() const |
| void | setBorderColor(QColor color) |
| void | setBorderWidth(qreal borderWidth) |
| void | setColor(QColor color) |
| void | setExplodeDistanceFactor(qreal factor) |
| void | setExploded(bool exploded) |
| void | setLabel(const QString &label) |
| void | setLabelArmLengthFactor(qreal factor) |
| void | setLabelColor(QColor color) |
| void | setLabelFont(const QFont &font) |
| void | setLabelPosition(QPieSlice::LabelPosition position) |
| void | setLabelVisible(bool visible = true) |
| void | setValue(qreal value) |
| qreal | startAngle() const |
| qreal | value() const |
| void | angleSpanChanged() |
| void | borderColorChanged() |
| void | borderWidthChanged() |
| void | colorChanged() |
| void | explodeDistanceFactorChanged() |
| void | explodedChanged() |
| void | labelArmLengthFactorChanged() |
| void | labelChanged() |
| void | labelColorChanged() |
| void | labelFontChanged() |
| void | labelPositionChanged() |
| void | labelVisibleChanged() |
| void | percentageChanged() |
| void | startAngleChanged() |
| void | valueChanged() |
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.
See also QPieSeries.
This enum describes the position of the slice label.
| Constant | Value | Description |
|---|---|---|
QPieSlice::LabelPosition::Outside |
0 |
The label is located outside the slice connected to it with an arm. This is the default value. |
QPieSlice::LabelPosition::InsideHorizontal |
1 |
The label is centered within the slice and laid out horizontally. |
QPieSlice::LabelPosition::InsideTangential |
2 |
The label is centered within the slice and rotated to be parallel with the tangential of the slice's arc. |
QPieSlice::LabelPosition::InsideNormal |
3 |
The label is centered within the slice and rotated to be parallel with the normal of the slice's arc. |
[read-only] angleSpan : const qrealThis 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:
| qreal | angleSpan() const |
Notifier signal:
| void | angleSpanChanged() |
This property holds the color used to draw the slice border. This is a convenience property for modifying the slice.
Access functions:
| QColor | borderColor() const |
| void | setBorderColor(QColor color) |
Notifier signal:
| void | borderColorChanged() |
See also borderWidth.
This property holds the width of the slice border. This is a convenience property for modifying the slice border width.
Access functions:
| qreal | borderWidth() const |
| void | setBorderWidth(qreal borderWidth) |
Notifier signal:
| void | borderWidthChanged() |
See also borderColor.
This property holds the fill color of the slice. This is a convenience property for modifying the slice fill color.
Access functions:
| QColor | color() const |
| void | setColor(QColor color) |
Notifier signal:
| void | colorChanged() |
Determines how far away from the pie the slice is exploded.
By default, the distance is 0.15
Access functions:
| qreal | explodeDistanceFactor() const |
| void | setExplodeDistanceFactor(qreal factor) |
Notifier signal:
| void | explodeDistanceFactorChanged() |
See also exploded.
This property holds whether the slice is separated from the pie.
Access functions:
| bool | isExploded() const |
| void | setExploded(bool exploded) |
Notifier signal:
| void | explodedChanged() |
See also explodeDistanceFactor.
This property holds the label of the slice.
Note: The string can be HTML formatted.
Access functions:
| QString | label() const |
| void | setLabel(const QString &label) |
Notifier signal:
| void | labelChanged() |
See also labelVisible, labelFont, and labelArmLengthFactor.
This property holds the length of the label arm. The factor is relative to the pie radius. For example:
By default, the arm length is 0.15
Access functions:
| qreal | labelArmLengthFactor() const |
| void | setLabelArmLengthFactor(qreal factor) |
Notifier signal:
| void | labelArmLengthFactorChanged() |
See also label, labelVisible, and labelFont.
This property holds the color used to draw the slice label.
Access functions:
| QColor | labelColor() const |
| void | setLabelColor(QColor color) |
Notifier signal:
| void | labelColorChanged() |
This property holds the font used for drawing the label text.
Access functions:
| QFont | labelFont() const |
| void | setLabelFont(const QFont &font) |
Notifier signal:
| void | labelFontChanged() |
See also label, labelVisible, and labelArmLengthFactor.
This property holds the position of the slice label.
Access functions:
| QPieSlice::LabelPosition | labelPosition() |
| void | setLabelPosition(QPieSlice::LabelPosition position) |
Notifier signal:
| void | labelPositionChanged() |
See also label and labelVisible.
This property holds the visibility of the slice label. By default, the label is not visible.
Access functions:
| bool | isLabelVisible() const |
| void | setLabelVisible(bool visible = true) |
Notifier signal:
| void | labelVisibleChanged() |
See also label, labelFont, and labelArmLengthFactor.
[read-only] percentage : const qrealThis 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.
Access functions:
| qreal | percentage() const |
Notifier signal:
| void | percentageChanged() |
See also value and QPieSeries::sum.
[read-only] startAngle : const qrealThis 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:
| qreal | startAngle() const |
Notifier signal:
| void | startAngleChanged() |
This property holds the value of the slice.
Note: A negative value is converted to a positive value.
Access functions:
| qreal | value() const |
| void | setValue(qreal value) |
Notifier signal:
| void | valueChanged() |
See also percentage() and QPieSeries::sum().
[explicit] QPieSlice::QPieSlice(QObject
*parent = nullptr)Constructs an empty slice with the parent parent.
See also QPieSeries::append() and QPieSeries::insert().
Constructs an empty slice with the specified value, label, and parent.
See also QPieSeries::append() and QPieSeries::insert().
[override virtual noexcept] QPieSlice::~QPieSlice()Removes the slice. The slice should not be removed if it has been added to a series.
Returns the series that this slice belongs to.
See also QPieSeries::append().