QDateTimeAxis Class
The QDateTimeAxis class is an axis of dates and times. More…
| Header | #include <QDateTimeAxis> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Charts) |
| Module | Nt Charts C++ Classes |
| Inherits | QAbstractAxis |
List of all members, including inherited members
Public Functions
| QDateTimeAxis(QObject *parent = nullptr) | |
| ~QDateTimeAxis() | |
| void | setMin(const QDateTime &min) |
| QDateTime | min() const |
| void | setMax(const QDateTime &max) |
| QDateTime | max() const |
| void | setRange(const QDateTime &min, const QDateTime &max) |
| void | setFormat(const QString &format) |
| QString | format() const |
| void | setTickCount(int count) |
| int | tickCount() const |
Reimplemented Public Functions
| AxisType | type() const |
Signals
| void | minChanged(QDateTime min) |
| void | maxChanged(QDateTime max) |
| void | rangeChanged(QDateTime min, QDateTime max) |
| void | formatChanged(const QString &format) |
| void | tickCountChanged(int tick) |
Reimplemented Protected Functions
| void | setRangeFromVariant(const QVariant &min, const QVariant &max) |
Detailed Description

The series attached to the axis give their x (or y) values in milliseconds since 1970-01-01T00:00:00 UTC, as QDateTime::toMSecsSinceEpoch() returns them. The axis has tickCount() ticks spread evenly over its range, with labels written with format():
auto *series = new QLineSeries;
series->append(QDateTime::currentDateTime().toMSecsSinceEpoch(), cpuLoad());
auto *axisX = new QDateTimeAxis;
axisX->setFormat("hh:mm:ss");
axisX->setTickCount(6);
chart->addAxis(axisX, Qt::AlignBottom);
series->attachAxis(axisX);
See also QValueAxis and QDateTime::toString().
Differences from Qt
The labels are written in local time.
Member Function Documentation
QDateTimeAxis::QDateTimeAxis(QObject *parent = nullptr)
Constructs a date and time axis with the given parent.
QDateTimeAxis::~QDateTimeAxis()
Destroys the axis.
QString QDateTimeAxis::format() const
Returns the format of the labels.
void QDateTimeAxis::formatChanged(const QString &format)
This signal is emitted when the format of the labels changes to format.
QDateTime QDateTimeAxis::max() const
Returns the maximum of the axis.
void QDateTimeAxis::maxChanged(QDateTime max)
This signal is emitted when the maximum of the axis changes to max.
QDateTime QDateTimeAxis::min() const
Returns the minimum of the axis.
void QDateTimeAxis::minChanged(QDateTime min)
This signal is emitted when the minimum of the axis changes to min.
void QDateTimeAxis::rangeChanged(QDateTime min, QDateTime max)
This signal is emitted when the range of the axis changes to min and max.
void QDateTimeAxis::setFormat(const QString &format)
Sets the format of the labels to format, as QDateTime::toString() reads it. The default is "dd-MM-yyyy h:mm".
void QDateTimeAxis::setMax(const QDateTime &max)
Sets the maximum of the axis to max. The minimum shrinks to max if it is later.
void QDateTimeAxis::setMin(const QDateTime &min)
Sets the minimum of the axis to min. The maximum grows to min if it is earlier.
void QDateTimeAxis::setRange(const QDateTime &min, const QDateTime &max)
Sets the range of the axis to min and max. A range that ends before it starts is ignored.
void QDateTimeAxis::setRangeFromVariant(const QVariant &min, const QVariant &max)
Reimplements QAbstractAxis::setRangeFromVariant().
Sets the range to min and max, converted to QDateTime. An invalid variant leaves that end as it is.
void QDateTimeAxis::setTickCount(int count)
Sets the number of ticks to count, at least 2.
int QDateTimeAxis::tickCount() const
Returns the number of ticks. The default is 5.
void QDateTimeAxis::tickCountChanged(int tick)
This signal is emitted when the number of ticks changes to tick.
AxisType QDateTimeAxis::type() const
Reimplements QAbstractAxis::type().
Returns QAbstractAxis::AxisTypeDateTime.