QDateTimeAxis of QT learning

The QDateTimeAxis class adds date and time to a chart's axes. DateTimeAxis can be set to display an axis with tick marks, grid lines and shading . Labels can be configured by setting the appropriate DateTime format . QDateTimeAxis correctly handles dates from 4714 BCE to 287396 CE. See the QDateTime documentation for other limitations of QDateTime.

QDateTimeAxis can be used with any QXYSeries . To add data points to the series, use 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);

The code snippet below illustrates how to add the series to the chart and set the 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);
Header: #include <QDateTimeAxis>
Instantiated By: DateTimeAxis
Inherits: QAbstractAxis

Properties

  • format  : QString This property holds the format string used when creating axis labels from QDateTime objects.
  • max  : QDateTime This property holds the maximum value on the axis.
  • min  : QDateTime This property holds the minimum value on the axis.
  • tickCount  : int This property holds the number of tick marks on the axis.

Public Functions

QDateTimeAxis(QObject *parent = nullptr)
virtual ~QDateTimeAxis ()
QString format() const 

This property holds the format string used when creating axis labels from QDateTime objects.

QDateTime max () const This property holds the maximum value on the axis.
QDateTime min () const This property holds the minimum value on the axis.
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 This property holds the number of tick marks on the axis.

 Signals

void formatChanged(QString format

This signal is emitted when the format of an axis changes.

void

maxChanged(QDateTime max)

This signal is emitted when the maximum value of the axis (specified by min) changes.

void

minChanged(QDateTime min

This signal is emitted when the minimum value of the axis (specified by min) changes.

void

rangeChanged(QDateTime min, QDateTime max)

This signal is emitted when the minimum or maximum value of the axis specified by min and max changes.

void

tickCountChanged(int tickCount)

This signal is emitted when the number of tick marks on the axis specified by tickCount has changed.

QDateTime 

The QDateTime class provides date and time functions. DateTime objects encode calendar dates and clock times ("datetimes"). It combines the features of QDate and QTime classes. It can read the current date-time from the system clock. It provides functions for comparing datetimes and manipulating datetimes by adding seconds, days, months or years.

QDateTime can be combined with the QTimeZone class to describe a date-time relative to local time , UTC , a specified offset from UTC , or a specified time zone . For example, the "Europe/Berlin" time zone will apply the daylight saving rules used in Germany since 1970. In contrast, an offset from UTC +3600 seconds is one hour ahead of UTC (often written "UTC+01:00" in ISO standard notation), with no daylight saving time offset or change. Time zone transitions (such as Daylight Saving Time (DST; but see below) when using local time or specifying a time zone. The choice of a system for representing datetimes is described as its "timespec".

QDateTime objects are usually created by giving the date and time explicitly in the constructor, or by using static functions such as currentDateTime () or fromMSecsSceEpoch (). The date and time can be changed using setDate () and setTime (). The datetime can also be set using the setMSecsSinceEpoch () function, which gets the time in milliseconds since January 1, 1970 00:00:00. The fromString () function returns a QDateTime given a string and a date format for interpreting the dates in the string.

Guess you like

Origin blog.csdn.net/qq_44632658/article/details/131699816