6.0.0-rc4Source

QBarSet Class

The QBarSet class is one set of values of a bar series, drawn as bars of one color. More…

Header#include <QBarSet>
CMaketarget_link_libraries(app PRIVATE Nt::Charts)
ModuleNt Charts C++ Classes
InheritsQObject

List of all members, including inherited members

Public Functions

QBarSet(const QString &label, QObject *parent = nullptr)
~QBarSet()
voidsetLabel(const QString &label)
QStringlabel() const
voidappend(const qreal value)
voidappend(const QList<qreal> &values)
QBarSet &operator<<(const qreal &value)
voidinsert(const int index, const qreal value)
voidremove(const int index, const int count = 1)
voidreplace(const int index, const qreal value)
qrealat(const int index) const
qrealoperator[](const int index) const
intcount() const
qrealsum() const
voidsetPen(const QPen &pen)
QPenpen() const
voidsetBrush(const QBrush &brush)
QBrushbrush() const
voidsetLabelBrush(const QBrush &brush)
QBrushlabelBrush() const
voidsetLabelFont(const QFont &font)
QFontlabelFont() const
QColorcolor()
voidsetColor(QColor color)
QColorborderColor()
voidsetBorderColor(QColor color)
QColorlabelColor()
voidsetLabelColor(QColor color)

Signals

voidclicked(int index)
voidhovered(bool status, int index)
voidpressed(int index)
voidreleased(int index)
voiddoubleClicked(int index)
voidpenChanged()
voidbrushChanged()
voidlabelChanged()
voidlabelBrushChanged()
voidlabelFontChanged()
voidcolorChanged(QColor color)
voidborderColorChanged(QColor color)
voidlabelColorChanged(QColor color)
voidvaluesAdded(int index, int count)
voidvaluesRemoved(int index, int count)
voidvalueChanged(int index)

Detailed Description

Value i of the set is drawn at category i of the series. A bar series with several sets draws them side by side (QBarSeries), stacked (QStackedBarSeries) or as shares of the total (QPercentBarSeries), and the legend shows one entry per set, with its label().

auto *done = new QBarSet("Done");
*done << 12 << 18 << 9 << 15;
auto *open = new QBarSet("Open");
*open << 4 << 6 << 3 << 8;

auto *series = new QBarSeries;
series->append(done);
series->append(open);
series->setLabelsVisible(true);
QObject::connect(series, &QBarSeries::clicked, [](int index, QBarSet *set) {
    std::printf("%s: %g\n", set->label().toUtf8().constData(), set->at(index));
});

auto *axisX = new QBarCategoryAxis;
axisX->append({"Core", "GUI", "Network", "Charts"});
auto *axisY = new QValueAxis;
axisY->setRange(0, 20);

auto *chart = new QChart;
chart->setTitle("Tickets");
chart->addSeries(series);
chart->addAxis(axisX, Qt::AlignBottom);
chart->addAxis(axisY, Qt::AlignLeft);
series->attachAxis(axisX);
series->attachAxis(axisY);

See also QAbstractBarSeries and QBarCategoryAxis.

Differences from Qt

The set is not drawn with a gradient or a texture: only the color of its brush is used.

Member Function Documentation

[explicit] QBarSet::QBarSet(const QString &label, QObject *parent = nullptr)

Constructs an empty set called label, with the given parent.

[override] QBarSet::~QBarSet()

Destroys the set and removes it from its series.

void QBarSet::append(const qreal value)

Appends value.

void QBarSet::append(const QList<qreal> &values)

This is an overloaded function.

Appends values.

qreal QBarSet::at(const int index) const

Returns the value at index, or 0 if there is none.

QColor QBarSet::borderColor()

Returns the color of the borders of the bars.

[signal] void QBarSet::borderColorChanged(QColor color)

This signal is emitted when the border color changes to color.

QBrush QBarSet::brush() const

Returns the brush of the bars. Unless one was set, it has the color the theme gives the set.

[signal] void QBarSet::brushChanged()

This signal is emitted when the brush of the bars changes.

[signal] void QBarSet::clicked(int index)

This signal is emitted when the user clicks the bar at index.

QColor QBarSet::color()

Returns the fill color of the bars.

[signal] void QBarSet::colorChanged(QColor color)

This signal is emitted when the fill color changes to color.

int QBarSet::count() const

Returns the number of values.

[signal] void QBarSet::doubleClicked(int index)

This signal is emitted when the user double-clicks the bar at index.

[signal] void QBarSet::hovered(bool status, int index)

This signal is emitted when the mouse enters or leaves the bar at index; status is true when it enters.

void QBarSet::insert(const int index, const qreal value)

Inserts value at index. An index out of range appends it.

QString QBarSet::label() const

Returns the label of the set.

QBrush QBarSet::labelBrush() const

Returns the brush of the value labels.

[signal] void QBarSet::labelBrushChanged()

This signal is emitted when the brush of the value labels changes.

[signal] void QBarSet::labelChanged()

This signal is emitted when the label of the set changes.

QColor QBarSet::labelColor()

Returns the color of the value labels.

[signal] void QBarSet::labelColorChanged(QColor color)

This signal is emitted when the color of the value labels changes to color.

QFont QBarSet::labelFont() const

Returns the font of the value labels.

[signal] void QBarSet::labelFontChanged()

This signal is emitted when the font of the value labels changes.

QBarSet & QBarSet::operator<<(const qreal &value)

Appends value and returns a reference to the set.

qreal QBarSet::operator[](const int index) const

Returns the value at index, or 0 if there is none.

QPen QBarSet::pen() const

Returns the pen of the borders of the bars.

[signal] void QBarSet::penChanged()

This signal is emitted when the pen of the bars changes.

[signal] void QBarSet::pressed(int index)

This signal is emitted when the user presses a mouse button on the bar at index.

[signal] void QBarSet::released(int index)

This signal is emitted when the user releases a mouse button on the bar at index.

void QBarSet::remove(const int index, const int count = 1)

Removes count values, starting at index.

void QBarSet::replace(const int index, const qreal value)

Replaces the value at index with value.

void QBarSet::setBorderColor(QColor color)

Sets the color of the borders of the bars to color.

void QBarSet::setBrush(const QBrush &brush)

Sets the brush of the bars to brush.

void QBarSet::setColor(QColor color)

Sets the fill color of the bars to color.

void QBarSet::setLabel(const QString &label)

Sets the label of the set to label. The legend shows it.

void QBarSet::setLabelBrush(const QBrush &brush)

Sets the brush of the value labels to brush.

void QBarSet::setLabelColor(QColor color)

Sets the color of the value labels to color.

void QBarSet::setLabelFont(const QFont &font)

Sets the font of the value labels to font.

void QBarSet::setPen(const QPen &pen)

Sets the pen of the borders of the bars to pen.

qreal QBarSet::sum() const

Returns the sum of the values.

[signal] void QBarSet::valueChanged(int index)

This signal is emitted when the value at index changes.

[signal] void QBarSet::valuesAdded(int index, int count)

This signal is emitted when count values are added, starting at index.

[signal] void QBarSet::valuesRemoved(int index, int count)

This signal is emitted when count values are removed, starting at index.