Refreshing a Custom QwtScaleDraw
Hi, I have reimplemented QwtScaleDraw.
When I start plotting data I would like the current time to be displayed. Not the time when the application started.
I reset my QTime, It does eventually display the right time after the plot starts to auto scale.
Thanks in advance
Brendan
Code:
{
public:
TimeScaleDraw();
void start();
virtual QwtText label
(double) const;
private:
};
TimeScaleDraw::TimeScaleDraw()
{
start();
}
QwtText TimeScaleDraw
::label(double v
) const {
QTime upTime
= m_base_time.
addMSecs((int)v
);
return upTime.toString("H:mm:ss.zzz");
}
void TimeScaleDraw::start()
{
m_base_time.start();
//TODO: DO SOMETHING HERE TO REFRESH QwtScaleDraw???
}
Re: Refreshing a Custom QwtScaleDraw
Re: Refreshing a Custom QwtScaleDraw
I tried calling qwtPlot->replot() after start() was called, this didn't make any difference.
I have also tried passing the QwtPlot pointer to the class and running replot() with that pointer. This didn't make any difference.
When I added QwtPlot::replot() to the class it gave the following error:
"cannot call member function 'virtual void QwtPlot::replot()' without object"
I tried adding friend classes etc.
I don't seem to have the same problem with my custom QwtPlotPicker.
Please excuse my stupidity in advance :)
Re: Refreshing a Custom QwtScaleDraw
Code:
TimeScaleDraw* scaleDraw = dynamic_cast<TimeScaleDraw*>( plot->axisScaleDraw( ... ) );
scaleDraw->start();
scaleDraw->invalidateCache();
plot->replot();
HTH,
Uwe
Re: Refreshing a Custom QwtScaleDraw
The scaleDraw->invalidateCache() gives a protected error when compiling.
If I put invalidateCache() inside a new function that changes appearance in TimeScaleDraw class: eg ms, sec, clock etc it changes straight away.
However if invalidateCache() is put in the end of start() time still doesn't update until the plot starts moving etc. I guess this isn't too much of an issue.
I just use the following for time atm:
Code:
QwtText TimeScaleDraw
::label(double /*v*/) const {
return m_base_time.toString("H:mm:ss.zzz");
}
Re: Refreshing a Custom QwtScaleDraw
The call to invalidateCache() won't cause a replot on its own, it is just a method to ensure that the labels are recalculated the next time there -is- a replot. So after you construct your TimeScaleDraw class, call replot() from where ever you are in the code.
Re: Refreshing a Custom QwtScaleDraw
Yeah I was calling replot() last but made no difference.