I have a QwtDateScaleDraw on my x-axis. When I zoom out my xAxis shows me dates like:
"08:44:00
Fr 28 Jan 1916"
actually it should be
"08:44:00
28.01.16"
when I zoom in again, it has the right Format again
{
time = time.fromString(m_time, "hh:mm:ss");
date = date.fromString(m_date, "dd.MM.yy");
datetime.setDate(date);
datetime.setTime(time);
return QwtDate::toDouble(datetime);
}
double MonitorPlot::getXPoint(QString m_date, QString m_time)
{
QDateTime datetime;
QDate date;
QTime time;
time = time.fromString(m_time, "hh:mm:ss");
date = date.fromString(m_date, "dd.MM.yy");
datetime.setDate(date);
datetime.setTime(time);
return QwtDate::toDouble(datetime);
}
To copy to clipboard, switch view to plain text mode
#define TIMESTRINGFORMAT "hh:mm:ss"
#define DATESTRINGFORMAT "dd.MM.yy"
{
plot->setCanvasBackground(Qt::white);
liveGrid
->setMajorPen
( QPen( Qt
::gray,
0, Qt
::DotLine ) );
liveGrid
->setMinorPen
( QPen( Qt
::gray,
0 , Qt
::DotLine ) );
liveGrid->attach(plot);
plot
->setAxisAutoScale
(QwtPlot::yLeft,
true);
QwtDateScaleDraw *scaleDraw = new QwtDateScaleDraw( Qt::LocalTime );
scaleDraw
->setDateFormat
(QwtDate
::Millisecond,
QString("%1%2%3").
arg(TIMESTRINGFORMAT
).
arg("\n").
arg(DATESTRINGFORMAT
));
plot
->setAxisScaleDraw
(QwtPlot::xBottom, scaleDraw
);
//plot->enableAxis(QwtPlot::xBottom, false);
setLegend(plot);
connect( plot
->axisWidget
( QwtPlot::xBottom ),
SIGNAL( scaleDivChanged
() ),
SLOT( scaleDivChanged
() ) );
return plot;
}
#define TIMESTRINGFORMAT "hh:mm:ss"
#define DATESTRINGFORMAT "dd.MM.yy"
QwtPlot *MonitorPlot::getPlot()
{
QwtPlot *plot;
plot = new QwtPlot(this);
plot->setCanvasBackground(Qt::white);
QwtPlotGrid *liveGrid = new QwtPlotGrid();
liveGrid->setMajorPen( QPen( Qt::gray, 0, Qt::DotLine ) );
liveGrid->setMinorPen( QPen( Qt::gray, 0 , Qt::DotLine ) );
liveGrid->attach(plot);
plot->setAxisAutoScale(QwtPlot::yLeft, true);
QwtDateScaleDraw *scaleDraw = new QwtDateScaleDraw( Qt::LocalTime );
scaleDraw->setDateFormat(QwtDate::Millisecond, QString("%1%2%3").arg(TIMESTRINGFORMAT).arg("\n").arg(DATESTRINGFORMAT));
plot->setAxisScaleDraw(QwtPlot::xBottom, scaleDraw);
//plot->enableAxis(QwtPlot::xBottom, false);
setLegend(plot);
connect( plot->axisWidget( QwtPlot::xBottom ), SIGNAL( scaleDivChanged() ), SLOT( scaleDivChanged() ) );
return plot;
}
To copy to clipboard, switch view to plain text mode
Bookmarks