QDateTimeAxis Class
QDateTimeAxis 类用于在图表的坐标轴上添加日期和时间。更多内容...
| Header: | #include <QDateTimeAxis> |
| In QML: | DateTimeAxis |
| Inherits: | QAbstractAxis |
| Status: | Deprecated |
该类已弃用。我们强烈建议不要在新代码中使用它。
属性
公共函数
| QDateTimeAxis(QObject *parent = nullptr) | |
| virtual | ~QDateTimeAxis() |
| QString | format() const |
| QDateTime | max() const |
| QDateTime | min() const |
| void | setFormat(QString format) |
| void | setMax(QDateTime max) |
| void | setMin(QDateTime min) |
| void | setRange(QDateTime min, QDateTime max) |
| void | setTickCount(int count) |
| int | tickCount() const |
重新实现的公共函数
| virtual QAbstractAxis::AxisType | type() const override |
信号
| void | formatChanged(QString format) |
| void | maxChanged(QDateTime max) |
| void | minChanged(QDateTime min) |
| void | rangeChanged(QDateTime min, QDateTime max) |
| void | tickCountChanged(int tickCount) |
详细说明
QDateTimeAxis 可以配置为显示带有刻度、网格线和阴影的坐标轴。可以通过设置适当的 DateTime 格式来配置标签。QDateTimeAxis 能正确处理从公元前 4714 年到公元 287396 年的日期。有关QDateTime 的其他限制,请参阅QDateTime 文档。
注意: 在将 qreal 定义为 float 的平台上,QDateTimeAxis 会被禁用。

QDateTimeAxis 可与任何QXYSeries 配合使用。要向数据系列添加数据点,请使用QDateTime::toMSecsSinceEpoch():
QLineSeries *series = new QLineSeries;
QDateTime xValue;
xValue.setDate(QDate(2012, 1 , 18));
xValue.setTime(QTime(9, 34));
qreal yValue = 12;
series->append(xValue.toMSecsSinceEpoch(), yValue);
xValue.setDate(QDate(2013, 5 , 11));
xValue.setTime(QTime(11, 14));
qreal yValue = 22;
series->append(xValue.toMSecsSinceEpoch(), yValue);以下代码片段演示了将数据系列添加到图表以及设置 QDateTimeAxis 的方法:
QChartView *chartView = new QChartView;
chartView->chart()->addSeries(series);
// ...
QDateTimeAxis *axisX = new QDateTimeAxis;
axisX->setFormat("dd-MM-yyyy h:mm");
chartView->chart()->setAxisX(axisX, series);属性文档
format : QString
该属性存储用于根据QDateTime 对象创建坐标轴标签时的格式字符串。
有关该字符串的定义方法,请参阅QDateTime 文档。
访问函数:
| QString | format() const |
| void | setFormat(QString format) |
通知信号:
| void | formatChanged(QString format) |
另请参阅 QChart::locale 。
max : QDateTime
该属性存储轴上的最大值。
设置此属性时,系统会根据需要调整最小值,以确保该范围仍然有效。
访问函数:
| QDateTime | max() const |
| void | setMax(QDateTime max) |
通知信号:
| void | maxChanged(QDateTime max) |
min : QDateTime
该属性存储轴上的最小值。
设置此属性时,系统会根据需要调整最大值,以确保范围保持有效。
访问函数:
| QDateTime | min() const |
| void | setMin(QDateTime min) |
通知信号:
| void | minChanged(QDateTime min) |
tickCount : int
该属性用于指定轴上的刻度线数量。
访问函数:
| int | tickCount() const |
| void | setTickCount(int count) |
通知信号:
| void | tickCountChanged(int tickCount) |
成员函数文档
[explicit] QDateTimeAxis::QDateTimeAxis(QObject *parent = nullptr)
创建一个作为parent 子节点的轴对象。
[virtual noexcept] QDateTimeAxis::~QDateTimeAxis()
销毁该对象。
[signal] void QDateTimeAxis::formatChanged(QString format)
当该轴的format 属性发生变化时,会发出此信号。
注意: 这是属性format的通知器 信号。
[signal] void QDateTimeAxis::maxChanged(QDateTime max)
当由max 指定的轴的最大值发生变化时,会触发此信号。
注意: 这是属性max 的Notifier 信号。
[signal] void QDateTimeAxis::minChanged(QDateTime min)
当由min 指定的轴的最小值发生变化时,将触发此信号。
注意: 这是属性min 的Notifier 信号。
[signal] void QDateTimeAxis::rangeChanged(QDateTime min, QDateTime max)
当由 `min ` 和 `max` 指定的轴的最小值或最大值发生变化时,会发出此信号。
void QDateTimeAxis::setRange(QDateTime min, QDateTime max)
将轴上的范围设置为min 到max 。如果min 大于max ,则该函数不进行任何更改并返回。
void QDateTimeAxis::setTickCount(int count)
将轴上的刻度数设置为count 。
注意: 这是属性tickCount 的设置 函数。
另请参阅 tickCount()。
int QDateTimeAxis::tickCount() const
返回轴上的刻度数量。
注意: 这是 tickCount 属性的获取函数 。
另请参阅 setTickCount()。
[signal] void QDateTimeAxis::tickCountChanged(int tickCount)
当由tickCount 指定的坐标轴刻度数发生变化时,会触发此信号。
注意: 这是属性tickCount的通知器 信号。
[override virtual] QAbstractAxis::AxisType QDateTimeAxis::type() const
重写了:QAbstractAxis::type() const。
返回轴的类型。
© 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.