I inherit class from QwtScaleDraw to show date-time axis:
public:
TimeScaleDraw
(const QDateTime &base
) : baseDateTime
(base
)
{
setLabelRotation(0);
setLabelAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
setSpacing(20);
}
virtual QwtText label
(double v
) const {
dateTime = dateTime.fromTime_t(v);
return dateTime.toString("yyyy.MM.dd\nhh:mm:ss");
}
private:
};
class TimeScaleDraw: public QwtScaleDraw {
public:
TimeScaleDraw(const QDateTime &base) : baseDateTime(base)
{
setLabelRotation(0);
setLabelAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
setSpacing(20);
}
virtual QwtText label(double v) const
{
QDateTime dateTime;
dateTime = dateTime.fromTime_t(v);
return dateTime.toString("yyyy.MM.dd\nhh:mm:ss");
}
private:
QDateTime baseDateTime;
};
To copy to clipboard, switch view to plain text mode
In main file I use it as:
funPlot
->setAxisScaleDraw
(QwtPlot::xBottom,
new TimeScaleDraw
(QDateTime::currentDateTime()));
funPlot->setAxisScaleDraw(QwtPlot::xBottom, new TimeScaleDraw(QDateTime::currentDateTime()));
To copy to clipboard, switch view to plain text mode
I want to see the current date-time by default when I run the app. Is it possible? Now it displays as 1970.01.00 00:00:00 with an appropriate scale.
Bookmarks