PieSlice QML Type
表示饼图系列中的单个扇区。更多...
| Import Statement: | import QtGraphs |
| In C++: | QPieSlice |
- 所有成员的列表,包括继承的成员
- PieSlice 是Qt Graphs 2D QML 类型的一部分。
属性
- 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
信号
- 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()
方法
- PieSlice append(string label, real value)
- PieSlice at(int index)
- void 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)
详细说明
每个扇区都有一个数值和一个标签。当该扇区被添加到饼图系列中时,PieSeries 类型会计算该扇区相对于该系列中所有扇区总和的百分比,从而确定该扇区在图表中的实际大小。
默认情况下,标签处于隐藏状态。如果显示标签,则可将其置于扇区外并用连接线与扇区相连,或将其水平居中于扇区内部,或使其与扇区弧线的切线或法线平行。
默认情况下,扇区的视觉外观由主题决定,但可以通过指定扇区属性来覆盖该主题。不过,如果在自定义扇区后更改了主题,所有自定义设置都将丢失。
PieSlice 类型应作为PieSeries 类型的子元素使用。例如:
此外,还可以通过调用PieSeries.append()方法将扇区添加到饼图系列中。
在这种情况下,可以使用 `PieSeries.at()` 或 `PieSeries.find()` 访问单个 `PieSlice` 实例的属性。
一个扇区可以包含子扇区。
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"
}
}
另请参阅 PieSeries 。
属性文档
angleSpan : real [read-only]
该扇区的角度范围。一个完整的圆为360度,其中0度位于12点钟方向。该值会在扇区添加到系列后自动更新。
borderColor : color
用于绘制切片边框的颜色。
另请参阅 borderWidth 。
borderWidth : real
切片边框的宽度。这是一个用于修改切片边框宽度的便捷属性。
另请参阅 borderColor 。
color : color
切片的填充颜色。
explodeDistanceFactor : real
确定扇形片从圆饼处向外展开的距离。
- 1.0 表示该距离等于半径。
- 0.5 表示该距离为半径的一半。
默认距离为 0.15
另请参阅 exploded 。
exploded : bool
这块切片是否已从整块派上取下。
另请参阅 explodeDistanceFactor 。
label : string
切片的标签。
注意:该 字符串可以使用 HTML 格式。
labelArmLengthFactor : real
标签臂的长度。该系数是相对于饼图半径而言的。例如:
- 1.0 表示该长度与半径相等。
- 0.5 表示长度为半径的一半。
默认情况下,标签臂长度为 0.15
另请参阅 labelVisible 。
labelColor : color
用于绘制切片标签的颜色。
labelFont : font
切片标签所使用的字体。
有关更多信息,请参阅font 。
另请参阅 labelVisible 和labelPosition 。
labelPosition : enumeration
描述切片标签的位置。
| 常量 | 描述 |
|---|---|
PieSlice.LabelPosition.Outside | 标签位于与其通过一条连线相连的切片之外。这是默认值。 |
PieSlice.LabelPosition.InsideHorizontal | 标签位于切片中心,并水平排列。 |
PieSlice.LabelPosition.InsideTangential | 标签位于切片中心,并旋转至与切片弧的切线平行。 |
PieSlice.LabelPosition.InsideNormal | 标签位于切片中心,并旋转至与切片弧的法线平行。 |
另请参阅 labelVisible 。
labelVisible : bool
切片标签的可见性。默认情况下,该标签不可见。
percentage : real [read-only]
该切片占该系列所有切片总和的百分比。实际值范围为 0.0 到 1.0。切片添加到系列后,该值会自动更新。
startAngle : real [read-only]
该切片在其所属系列中的起始角度。一个完整的圆为360度,其中0度位于12点钟方向。该切片被添加到系列后,该数值会自动更新。
subSlicesCount : int [read-only]
该切片中的子切片数量。
subSlicesSum : real [read-only]
所有子切片的和。
该切片会记录其所包含的所有子切片的总和。
value : real
切片的值。
注意:负值 将被转换为正值。
信号文档
angleSpanChanged()
当切片的角度范围发生变化时,会发出此信号。
注意: 相应的处理程序 为onAngleSpanChanged 。
另请参阅 angleSpan 。
borderColorChanged()
当切片边框颜色发生变化时,会触发此信号。
注意: 相应的处理程序 为onBorderColorChanged 。
另请参阅 borderColor 。
borderWidthChanged()
当切片边框宽度发生变化时,会触发此信号。
注意: 相应的处理程序 为onBorderWidthChanged 。
另请参阅 borderWidth 。
colorChanged()
当切片颜色发生变化时,会触发此信号。
注意: 相应的处理程序 为onColorChanged 。
explodeDistanceFactorChanged()
当爆炸距离因子发生变化时,会触发此信号。
注意: 相应的处理程序 为onExplodeDistanceFactorChanged 。
另请参阅 explodeDistanceFactor 。
explodedChanged()
当“exploded”属性发生变化时,会触发此信号。
注意: 相应的处理程序 为onExplodedChanged 。
另请参阅 exploded 。
labelArmLengthFactorChanged()
当标签臂长度系数发生变化时,会发出此信号。
注意: 相应的处理程序 为onLabelArmLengthFactorChanged 。
另请参阅 labelArmLengthFactor 。
labelChanged()
当切片标签发生变化时,会发出此信号。
注意: 相应的处理程序 为onLabelChanged 。
另请参阅 label 。
labelColorChanged()
当切片标签颜色发生变化时,会触发此信号。
注意: 相应的处理程序 为onLabelColorChanged 。
另请参阅 labelColor 。
labelFontChanged()
当切片的标签字体发生变化时,会发出此信号。
注意: 相应的处理程序 为onLabelFontChanged 。
另请参阅 labelFont 。
labelFontChanged()
当标签字体发生变化时,会触发此信号。
注意: 相应的处理程序 为onLabelFontChanged 。
另请参阅 labelFont 。
labelPositionChanged()
当标签位置发生变化时,会触发此信号。
注意: 相应的处理程序 为onLabelPositionChanged 。
另请参阅 labelPosition 。
labelVisibleChanged()
当切片标签的可见性发生变化时,会发出此信号。
注意: 相应的处理程序 为onLabelVisibleChanged 。
另请参阅 labelVisible 。
percentageChanged()
当切片的百分比发生变化时,会触发此信号。
注意: 相应的处理程序 为onPercentageChanged 。
另请参阅 percentage 。
startAngleChanged()
当切片的起始角度发生变化时,会发出此信号。
注意: 相应的处理程序 为onStartAngleChanged 。
另请参阅 startAngle 。
subSlicesAdded(list<PieSlice> slices)
当由slices 指定的子切片被添加到该切片时,会发出此信号。
注意: 相应的处理程序 为onSubSlicesAdded 。
subSlicesCountChanged(qsizetype count)
当子切片count 发生变化时,会触发此信号。
注意: 相应的处理程序 是onSubSlicesCountChanged 。
另请参阅 subSlicesCount 。
subSlicesRemoved(list<PieSlice> slices)
当由slices 指定的子切片从切片中移除时,会发出此信号。
注意: 相应的处理程序 为onSubSlicesRemoved 。
subSlicesSumChanged(qreal sum)
当所有子切片的sum 发生变化时,会发出此信号。
注意: 相应的处理程序 为onSubSlicesSumChanged 。
另请参阅 subSlicesSum 。
valueChanged()
当切片值发生变化时,会触发此信号。
注意: 相应的处理程序 为onValueChanged 。
另请参阅 value 。
方法文档
PieSlice append(string label, real value)
向该切片添加一个新的子切片,其标签为label ,值为value 。
PieSlice at(int index)
返回位于index 指定位置的子切片。如果索引无效,则返回 null。
void clear()
从该切片中删除所有子切片。
PieSlice find(string label)
返回第一个带有标签label 的子片段。如果未找到该标签,则返回null。
bool remove(PieSlice slice)
从切片中移除由slice 指定的子切片。如果移除成功,则返回true ;否则返回false 。
bool remove(int index)
从切片中移除由index 指定的子切片。如果移除成功,则返回true ;否则返回false 。
void removeMultiple(int index, int count)
删除由index 和count 指定的子切片范围。即使其中一个子切片的删除操作失败,该调用仍会遍历所有子切片。
bool replace(PieSlice oldSlice, PieSlice newSlice)
将由oldSlice 指定的子切片替换为newSlice 。若替换成功,则返回true ;否则返回false 。若替换成功,则oldSlice 将被销毁。
bool replace(int index, PieSlice slice)
替换位于index 的切片中由slice 指定的子切片。如果替换成功,则返回true ;否则返回false 。
bool replaceAll(list<PieSlice> slices)
将所有当前子切片完全替换为slices 。尺寸无需匹配。如果slices 中的任何PieSlice 无效,则返回 false。
bool take(PieSlice slice)
从切片中获取一个由slice 指定的子切片。不会删除该子切片对象。若操作成功,则返回true 。
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.