QPieSlice Class

The QPieSlice class represents a single slice in a pie series. 更多...

头文件: #include <QPieSlice>
Instantiated By: PieSlice
基类: QObject

公有类型

enum LabelPosition { LabelOutside, LabelInsideHorizontal, LabelInsideTangential, LabelInsideNormal }

属性

公有函数

QPieSlice(QObject *parent = Q_NULLPTR)
QPieSlice(QString label, qreal value, QObject *parent = Q_NULLPTR)
virtual ~QPieSlice()
qreal angleSpan() const
QColor borderColor()
int borderWidth()
QBrush brush() const
QColor color()
qreal explodeDistanceFactor() const
bool isExploded() const
bool isLabelVisible() const
QString label() const
qreal labelArmLengthFactor() const
QBrush labelBrush() const
QColor labelColor()
QFont labelFont() const
LabelPosition labelPosition()
QPen pen() const
qreal percentage() const
QPieSeries *series() const
void setBorderColor(QColor color)
void setBorderWidth(int width)
void setBrush(const QBrush &brush)
void setColor(QColor color)
void setExplodeDistanceFactor(qreal factor)
void setExploded(bool exploded = true)
void setLabel(QString label)
void setLabelArmLengthFactor(qreal factor)
void setLabelBrush(const QBrush &brush)
void setLabelColor(QColor color)
void setLabelFont(const QFont &font)
void setLabelPosition(LabelPosition position)
void setLabelVisible(bool visible = true)
void setPen(const QPen &pen)
void setValue(qreal value)
qreal startAngle() const
qreal value() const
  • 32 个公有函数继承自 QObject

信号

其他继承的成员

  • 1 个公有槽函数继承自 QObject
  • 1 个公有变量继承自 QObject
  • 10 个静态公有成员继承自 QObject
  • 9 个受保护的函数继承自 QObject
  • 2 个受保护的变量继承自 QObject

详细描述

The QPieSlice class represents a single slice in a pie series.

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 chart.

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 chart, some basic signals are emitted when users click pie slices or hover the mouse over them.

参见 QPieSeries.

成员类型

enum QPieSlice::LabelPosition

This enum describes the position of the slice label.

ConstantValueDescription
QPieSlice::LabelOutside0The label is located outside the slice connected to it with an arm. This is the default value.
QPieSlice::LabelInsideHorizontal1The label is centered within the slice and laid out horizontally.
QPieSlice::LabelInsideTangential2The label is centered within the slice and rotated to be parallel with the tangential of the slice's arc.
QPieSlice::LabelInsideNormal3The label is centered within the slice and rotated to be parallel with the normal of the slice's arc.

属性

angleSpan : const qreal

This 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.

访问函数:

qreal angleSpan() const

Notifier signal:

borderColor : QColor

This property holds the color used to draw the slice border. This is a convenience property for modifying the slice pen.

访问函数:

QColor borderColor()
void setBorderColor(QColor color)

Notifier signal:

参见 pen and borderWidth.

borderWidth : int

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

访问函数:

int borderWidth()
void setBorderWidth(int width)

Notifier signal:

参见 pen and borderColor.

brush : QBrush

This property holds the brush used to fill the slice.

访问函数:

QBrush brush() const
void setBrush(const QBrush &brush)

Notifier signal:

void brushChanged()

color : QColor

This property holds the fill (brush) color of the slice. This is a convenience property for modifying the slice brush.

访问函数:

QColor color()
void setColor(QColor color)

Notifier signal:

void colorChanged()

参见 brush.

explodeDistanceFactor : qreal

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

访问函数:

qreal explodeDistanceFactor() const
void setExplodeDistanceFactor(qreal factor)

参见 exploded.

exploded : bool

This property holds whether the slice is separated from the pie.

访问函数:

bool isExploded() const
void setExploded(bool exploded = true)

参见 explodeDistanceFactor.

label : QString

This property holds the label of the slice.

访问函数:

QString label() const
void setLabel(QString label)

Notifier signal:

void labelChanged()

参见 labelVisible, labelBrush, labelFont, and labelArmLengthFactor.

labelArmLengthFactor : qreal

This property holds 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

访问函数:

qreal labelArmLengthFactor() const
void setLabelArmLengthFactor(qreal factor)

参见 label, labelVisible, labelBrush, and labelFont.

labelBrush : QBrush

This property holds the brush used to draw the label and label arm of the slice.

访问函数:

QBrush labelBrush() const
void setLabelBrush(const QBrush &brush)

Notifier signal:

参见 label, labelVisible, labelFont, and labelArmLengthFactor.

labelColor : QColor

This property holds the color used to draw the slice label. This is a convenience property for modifying the slice label brush.

访问函数:

QColor labelColor()
void setLabelColor(QColor color)

Notifier signal:

参见 labelBrush.

labelFont : QFont

This property holds the font used for drawing the label text.

访问函数:

QFont labelFont() const
void setLabelFont(const QFont &font)

Notifier signal:

参见 label, labelVisible, and labelArmLengthFactor.

labelPosition : LabelPosition

This property holds the position of the slice label.

访问函数:

LabelPosition labelPosition()
void setLabelPosition(LabelPosition position)

参见 label and labelVisible.

labelVisible : bool

This property holds the visibility of the slice label. By default, the label is not visible.

访问函数:

bool isLabelVisible() const
void setLabelVisible(bool visible = true)

Notifier signal:

参见 label, labelBrush, labelFont, and labelArmLengthFactor.

pen : QPen

This property holds the pen used to draw the slice border.

访问函数:

QPen pen() const
void setPen(const QPen &pen)

Notifier signal:

void penChanged()

percentage : const qreal

This 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.

访问函数:

qreal percentage() const

Notifier signal:

参见 value and QPieSeries::sum.

startAngle : const qreal

This 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.

访问函数:

qreal startAngle() const

Notifier signal:

value : qreal

This property holds the value of the slice.

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

访问函数:

qreal value() const
void setValue(qreal value)

Notifier signal:

void valueChanged()

参见 percentage() and QPieSeries::sum().

成员函数

QPieSlice::QPieSlice(QObject *parent = Q_NULLPTR)

Constructs an empty slice with the parent parent.

参见 QPieSeries::append() and QPieSeries::insert().

QPieSlice::QPieSlice(QString label, qreal value, QObject *parent = Q_NULLPTR)

Constructs an empty slice with the specified value, label, and parent.

参见 QPieSeries::append() and QPieSeries::insert().

[virtual] QPieSlice::~QPieSlice()

Removes the slice. The slice should not be removed if it has been added to a series.

[signal] void QPieSlice::angleSpanChanged()

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

Note: Notifier signal for property angleSpan.

参见 angleSpan.

[signal] void QPieSlice::borderColorChanged()

This signal is emitted when the slice border color changes.

Note: Notifier signal for property borderColor.

参见 pen and borderColor.

[signal] void QPieSlice::borderWidthChanged()

This signal is emitted when the slice border width changes.

Note: Notifier signal for property borderWidth.

参见 pen and borderWidth.

[signal] void QPieSlice::brushChanged()

This signal is emitted when the brush used to fill the slice changes.

Note: Notifier signal for property brush.

参见 brush.

[signal] void QPieSlice::clicked()

This signal is emitted when the slice is clicked.

参见 QPieSeries::clicked().

[signal] void QPieSlice::colorChanged()

This signal is emitted when the slice color changes.

Note: Notifier signal for property color.

参见 brush.

[signal] void QPieSlice::doubleClicked()

This signal is emitted when user double-clicks the slice.

参见 QPieSeries::doubleClicked().

[signal] void QPieSlice::hovered(bool state)

This signal is emitted when a mouse is hovered over the slice. When the mouse moves over the slice, state turns true, and when the mouse moves away again, it turns false.

参见 QPieSeries::hovered().

[signal] void QPieSlice::labelBrushChanged()

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

Note: Notifier signal for property labelBrush.

参见 labelBrush.

[signal] void QPieSlice::labelChanged()

This signal is emitted when the slice label changes.

Note: Notifier signal for property label.

参见 label.

[signal] void QPieSlice::labelColorChanged()

This signal is emitted when the slice label color changes.

Note: Notifier signal for property labelColor.

参见 labelColor.

[signal] void QPieSlice::labelFontChanged()

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

Note: Notifier signal for property labelFont.

参见 labelFont.

[signal] void QPieSlice::labelVisibleChanged()

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

Note: Notifier signal for property labelVisible.

参见 labelVisible.

[signal] void QPieSlice::penChanged()

This signal is emitted when the pen used to draw the slice border changes.

Note: Notifier signal for property pen.

参见 pen.

[signal] void QPieSlice::percentageChanged()

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

Note: Notifier signal for property percentage.

参见 percentage.

[signal] void QPieSlice::pressed()

This signal is emitted when the user clicks the slice and holds down the mouse button.

参见 QPieSeries::pressed().

[signal] void QPieSlice::released()

This signal is emitted when the user releases the mouse press on the slice.

参见 QPieSeries::released().

QPieSeries *QPieSlice::series() const

Returns the series that this slice belongs to.

参见 QPieSeries::append().

[signal] void QPieSlice::startAngleChanged()

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

Note: Notifier signal for property startAngle.

参见 startAngle.

[signal] void QPieSlice::valueChanged()

This signal is emitted when the slice value changes.

Note: Notifier signal for property value.

参见 value.