QPieSlice Class
QPieSlice 类表示派系列中的单片。更多
头文件: | #include <QPieSlice> |
CMake.QPieSlice | find_package(Qt6 REQUIRED COMPONENTS Graphs) target_link_libraries(mytarget PRIVATE Qt6::Graphs) |
qmake: | QT += graphs |
在 QML 中: | PieSlice |
继承: | QObject |
- 所有成员的列表,包括继承成员
- QPieSlice 是Qt Graphs C++ Classes for 2D 的一部分。
公共类型
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() |
详细说明
饼片有一个值和一个标签。当切片被添加到饼系列中时,QPieSeries 对象会计算该切片占该系列中所有切片总和的百分比,以确定该切片在图表中的实际大小。
默认情况下,标签是隐藏的。如果标签可见,它可以位于切片外侧并用一条臂与切片相连,也可以位于切片内侧水平居中或与切片圆弧的切线或法线平行居中。
默认情况下,切片的视觉外观由主题设置,但可以通过指定切片属性来覆盖主题。不过,如果在自定义切片后更改主题,所有自定义功能都将丢失。
为了实现用户与饼图的交互,当用户点击饼片或将鼠标悬停在饼片上时,会发出一些基本信号。
另请参阅 QPieSeries 。
成员类型文档
enum class QPieSlice::LabelPosition
该枚举描述切片标签的位置。
常数 | 值 | 描述 |
---|---|---|
QPieSlice::LabelPosition::Outside | 0 | 标签位于用臂连接的切片外部。这是默认值。 |
QPieSlice::LabelPosition::InsideHorizontal | 1 | 标签位于切片中心,水平放置。 |
QPieSlice::LabelPosition::InsideTangential | 2 | 标签位于切片中心,旋转后与切片圆弧的切线平行。 |
QPieSlice::LabelPosition::InsideNormal | 3 | 标签在切片内居中,旋转后与切片圆弧的法线平行。 |
属性文档
[read-only]
angleSpan : const qreal
该属性表示切片的度数跨度。一个完整的饼是 360 度,其中 0 度为 12 点钟方向。切片添加到系列后会自动更新。
访问功能:
qreal | angleSpan() const |
通知信号:
void | angleSpanChanged() |
borderColor : QColor
该属性保存用于绘制切片边框的颜色。这是一个方便修改切片的属性。
访问函数:
QColor | borderColor() const |
void | setBorderColor(QColor color) |
Notifier 信号:
void | borderColorChanged() |
另请参阅 borderWidth 。
borderWidth : qreal
该属性用于保存切片边框的宽度。这是一个方便修改切片边框宽度的属性。
访问函数:
qreal | borderWidth() const |
void | setBorderWidth(qreal borderWidth) |
通知信号:
void | borderWidthChanged() |
另请参见 borderColor 。
color : QColor
该属性用于保存切片的填充颜色。这是一个方便的属性,用于修改切片的填充颜色。
访问功能:
QColor | color() const |
void | setColor(QColor color) |
通知信号:
void | colorChanged() |
explodeDistanceFactor : qreal
决定切片爆炸时离饼的距离。
- 1.0 表示距离与半径相同。
- 0.5 表示距离是半径的一半。
默认距离为 0.15
访问功能:
qreal | explodeDistanceFactor() const |
void | setExplodeDistanceFactor(qreal factor) |
通知信号:
void | explodeDistanceFactorChanged() |
另请参见 exploded 。
exploded : bool
此属性表示切片是否从馅饼中分离出来。
访问功能:
bool | isExploded() const |
void | setExploded(bool exploded) |
Notifier 信号:
void | explodedChanged() |
另请参见 explodeDistanceFactor 。
label : QString
此属性包含切片的标签。
注意: 该字符串可以是 HTML 格式。
访问功能:
QString | label() const |
void | setLabel(const QString &label) |
Notifier 信号:
void | labelChanged() |
另请参阅 labelVisible,labelFont, 和labelArmLengthFactor 。
labelArmLengthFactor : qreal
此属性表示标签臂的长度。该系数相对于饼的半径。例如
- 1.0 表示长度与半径相同。
- 0.5 表示长度是半径的一半。
默认情况下,臂长为 0.15
访问功能:
qreal | labelArmLengthFactor() const |
void | setLabelArmLengthFactor(qreal factor) |
通知信号:
void | labelArmLengthFactorChanged() |
另请参见 label,labelVisible, 和labelFont 。
labelColor : QColor
该属性保存用于绘制切片标签的颜色。
访问功能:
QColor | labelColor() const |
void | setLabelColor(QColor color) |
通知信号:
void | labelColorChanged() |
labelFont : QFont
该属性用于保存绘制标签文本时使用的字体。
访问功能:
QFont | labelFont() const |
void | setLabelFont(const QFont &font) |
Notifier 信号:
void | labelFontChanged() |
另请参阅 label,labelVisible, 和labelArmLengthFactor 。
labelPosition : LabelPosition
该属性用于保存切片标签的位置。
访问功能:
QPieSlice::LabelPosition | labelPosition() |
void | setLabelPosition(QPieSlice::LabelPosition position) |
Notifier 信号:
void | labelPositionChanged() |
另请参阅 label 和labelVisible 。
labelVisible : bool
该属性用于设置切片标签的可见性。默认情况下,标签不可见。
访问功能:
bool | isLabelVisible() const |
void | setLabelVisible(bool visible = true) |
Notifier 信号:
void | labelVisibleChanged() |
另请参见 label,labelFont, 和labelArmLengthFactor 。
[read-only]
percentage : const qreal
该属性表示切片占系列中所有切片总和的百分比。实际值范围为 0.0 至 1.0。切片添加到系列后会自动更新。
访问功能:
qreal | percentage() const |
通知信号:
void | percentageChanged() |
另请参阅 value 和QPieSeries::sum 。
[read-only]
startAngle : const qreal
该属性表示该切片在其所属系列中的起始角度。一个完整的饼是 360 度,其中 0 度为 12 点钟方向。切片添加到系列后会自动更新。
访问功能:
qreal | startAngle() const |
通知信号:
void | startAngleChanged() |
value : qreal
该属性保存片段的值。
注意: 负值会转换为正值。
访问功能:
qreal | value() const |
void | setValue(qreal value) |
Notifier 信号:
void | valueChanged() |
另请参阅 percentage() 和QPieSeries::sum() 。
成员函数文档
[explicit]
QPieSlice::QPieSlice(QObject *parent = nullptr)
用父parent 构建一个空切片。
另请参阅 QPieSeries::append() 和QPieSeries::insert() 。
QPieSlice::QPieSlice(const QString &label, qreal value, QObject *parent = nullptr)
用指定的value,label, 和parent 构建一个空切片。
另请参阅 QPieSeries::append() 和QPieSeries::insert() 。
[override virtual noexcept]
QPieSlice::~QPieSlice()
删除片段。如果片段已添加到系列中,则不应删除。
QPieSeries *QPieSlice::series() const
返回此切片所属的系列。
另请参阅 QPieSeries::append()。
© 2025 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.