- Qt 6.11
- Qt Graphs
- QML Types
- QtGraphs
- PieSlice
- Qt Graphs | Commercial or GPLv3

# PieSlice QML Type

Represents a single slice in a pie series. More...

Import Statement: | `import QtGraphs`
In C++: | QPieSlice

- List of all members, including inherited members
- PieSlice is part of Qt Graphs QML Types for 2D.

## Properties

- angleSpan : real
- borderColor : color
- borderWidth : real
- color : color
- explodeDistanceFactor : real
- exploded : bool
- label : string
- labelArmLengthFactor : real
- labelColor : color
- labelFont : font
- labelPosition : enumeration
- labelVisible : bool
- percentage : real
- startAngle : real
- subSlicesCount : int
- subSlicesSum : real
- value : real

## Signals

- angleSpanChanged()
- borderColorChanged()
- borderWidthChanged()
- colorChanged()
- explodeDistanceFactorChanged()
- explodedChanged()
- labelArmLengthFactorChanged()
- labelChanged()
- labelColorChanged()
- labelFontChanged()
- labelFontChanged()
- labelPositionChanged()
- labelVisibleChanged()
- percentageChanged()
- startAngleChanged()
- subSlicesAdded(list<PieSlice> slices)
- subSlicesCountChanged(qsizetype count)
- subSlicesRemoved(list<PieSlice> slices)
- subSlicesSumChanged(qreal sum)
- valueChanged()

## Methods

- PieSlice append(string label, real value)
- PieSlice at(int index)
- clear()
- PieSlice find(string label)
- bool remove(PieSlice slice)
- bool remove(int index)
- void removeMultiple(int index, int count)
- bool replace(PieSlice oldSlice, PieSlice newSlice)
- bool replace(int index, PieSlice slice)
- bool replaceAll(list<PieSlice> slices)
- bool take(PieSlice slice)

## Detailed Description

A pie slice has a value and a label. When the slice is added to a pie series, the PieSeries type 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.

The PieSlice type should be used as a child of a PieSeries type. For example:

     PieSeries {
         PieSlice {
             label: "example"
             value: 1
         }
     }

Alternatively, slices can be added to a pie series by using the PieSeries.append() method.

In that case, PieSeries.at() or PieSeries.find() can be used to access the properties of an individual PieSlice instance.

A pie slice can contain sub slices.

     PieSeries {
         PieSlice {
             label: "example"
             value: 1
             color: "orange"
             exploded: true
             PieSlice {
                 label: "example2"
                 value: 2
                 color: "red"
             }
             PieSlice {
                 label: "example3"
                 value: 3
                 color: "yellow"
                 exploded: true
             }
         }
         PieSlice {
             label: "example4"
             value: 4
             color: "green"
         }
     }

See also PieSeries.

## Property Documentation

### angleSpan : real `[read-only]`

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.

### borderColor : color

The color used to draw the slice border.

See also borderWidth.

### borderWidth : real

The width of the slice border. This is a convenience property for modifying the slice border width.

See also borderColor.

### color : color

The fill color of the slice.

### explodeDistanceFactor : real

Determines how far away from the pie the slice is exploded.

- 1.0 means that the distance is the same as the radius.
- 0.5 means that the distance is half of the radius.

By default, the distance is 0.15

See also exploded.

### exploded : bool

Whether the slice is separated from the pie.

See also explodeDistanceFactor.

### label : string

The label of the slice.

Note: The string can be HTML formatted.

### labelArmLengthFactor : real

The length of the label arm. The factor is relative to the pie radius. For example:

- 1.0 means that the length is the same as the radius.
- 0.5 means that the length is half of the radius.

By default, the arm length is 0.15

See also labelVisible.

### labelColor : color

The color used to draw the slice label.

### labelFont : font

The font used for the slice label.

For more information, see font.

See also labelVisible and labelPosition.

### labelPosition : enumeration

Describes the position of the slice label.

Constant | Description
--- | ---
`PieSlice.LabelPosition.Outside` | The label is located outside the slice connected to it with an arm. This is the default value.
`PieSlice.LabelPosition.InsideHorizontal` | The label is centered within the slice and laid out horizontally.
`PieSlice.LabelPosition.InsideTangential` | The label is centered within the slice and rotated to be parallel with the tangential of the slice's arc.
`PieSlice.LabelPosition.InsideNormal` | The label is centered within the slice and rotated to be parallel with the normal of the slice's arc.

See also labelVisible.

### labelVisible : bool

The visibility of the slice label. By default, the label is not visible.

### percentage : real `[read-only]`

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.

### startAngle : real `[read-only]`

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.

### subSlicesCount : int `[read-only]`

The number of sub slices in the slice.

### subSlicesSum : real `[read-only]`

The sum of all sub slices.

The slice keeps track of the sum of all the sub slices it holds.

### value : real

The value of the slice.

Note: A negative value is converted to a positive value.

## Signal Documentation

### angleSpanChanged()

This signal is emitted when the angle span of the slice changes.

Note: The corresponding handler is `onAngleSpanChanged`.

See also angleSpan.

### borderColorChanged()

This signal is emitted when the slice border color changes.

Note: The corresponding handler is `onBorderColorChanged`.

See also borderColor.

### borderWidthChanged()

This signal is emitted when the slice border width changes.

Note: The corresponding handler is `onBorderWidthChanged`.

See also borderWidth.

### colorChanged()

This signal is emitted when the slice color changes.

Note: The corresponding handler is `onColorChanged`.

### explodeDistanceFactorChanged()

This signal is emitted when the explode distance factor changes.

Note: The corresponding handler is `onExplodeDistanceFactorChanged`.

See also explodeDistanceFactor.

### explodedChanged()

This signal is emitted when the exploded property changes.

Note: The corresponding handler is `onExplodedChanged`.

See also exploded.

### labelArmLengthFactorChanged()

This signal is emitted when the label arm length factor changes.

Note: The corresponding handler is `onLabelArmLengthFactorChanged`.

See also labelArmLengthFactor.

### labelChanged()

This signal is emitted when the slice label changes.

Note: The corresponding handler is `onLabelChanged`.

See also label.

### labelColorChanged()

This signal is emitted when the slice label color changes.

Note: The corresponding handler is `onLabelColorChanged`.

See also labelColor.

### labelFontChanged()

This signal is emitted when the label font of the slice changes.

Note: The corresponding handler is `onLabelFontChanged`.

See also labelFont.

### labelFontChanged()

This signal is emitted when the label font changes.

Note: The corresponding handler is `onLabelFontChanged`.

See also labelFont.

### labelPositionChanged()

This signal is emitted when the label position changes.

Note: The corresponding handler is `onLabelPositionChanged`.

See also labelPosition.

### labelVisibleChanged()

This signal is emitted when the visibility of the slice label changes.

Note: The corresponding handler is `onLabelVisibleChanged`.

See also labelVisible.

### percentageChanged()

This signal is emitted when the percentage of the slice changes.

Note: The corresponding handler is `onPercentageChanged`.

See also percentage.

### startAngleChanged()

This signal is emitted when the starting angle of the slice changes.

Note: The corresponding handler is `onStartAngleChanged`.

See also startAngle.

### subSlicesAdded(list<PieSlice> slices)

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

Note: The corresponding handler is `onSubSlicesAdded`.

### subSlicesCountChanged(qsizetype count)

This signal is emitted when the sub slices count changes.

Note: The corresponding handler is `onSubSlicesCountChanged`.

See also subSlicesCount.

### subSlicesRemoved(list<PieSlice> slices)

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

Note: The corresponding handler is `onSubSlicesRemoved`.

### subSlicesSumChanged(qreal sum)

This signal is emitted when the sum of all sub slices changes.

Note: The corresponding handler is `onSubSlicesSumChanged`.

See also subSlicesSum.

### valueChanged()

This signal is emitted when the slice value changes.

Note: The corresponding handler is `onValueChanged`.

See also value.

## Method Documentation

### PieSlice append(string label, real value)

Adds a new sub slice with the label label and the value value to the slice.

### PieSlice at(int index)

Returns the sub slice at the position specified by index. Returns null if the index is not valid.

### clear()

Removes all sub slices from the slice.

### PieSlice find(string label)

Returns the first sub slice that has the label label. Returns null if the label is not found.

### bool remove(PieSlice slice)

Removes the sub slice specified by slice from the slice. Returns `true` if the removal was successful, `false` otherwise.

### bool remove(int index)

Removes the sub slice specified by index from the slice. Returns `true` if the removal was successful, `false` otherwise.

### void removeMultiple(int index, int count)

Removes a range of sub slices as specified by the index and count. The call traverses over all sub slices even if removal of one fails.

### bool replace(PieSlice oldSlice, PieSlice newSlice)

Replaces the sub slice specified by oldSlice with newSlice. Returns `true` if the replace was successful, `false` otherwise. oldSlice is destroyed if it was replaced successfully.

### bool replace(int index, PieSlice slice)

Replaces the sub slice specified by slice from the slice at index. Returns `true` if the replace was successful, `false` otherwise.

### bool replaceAll(list<PieSlice> slices)

Completely replaces all current sub slices with slices. The size does not need to match. Returns false if any of the PieSlice in slices is invalid.

### bool take(PieSlice slice)

Takes a single sub slice, specified by slice, from the slice. Does not delete the sub slice object. Returns `true` if successful.