Using a zoomer to generate horizontal scrolling without zoom
I'm using QWT 6.0.0.0 RC5, QT 4.7.1.
I'm trying to generate the effect of horizontal scrolling for my plot - the X scale will be Time so it should be growing horizontally.
I saw a discussion in which it was advised to use the QwtPlotZoomer class, so right now I have a combination of the Oscilloscope and the Realtime examples.
What I want to achieve is to update the scale to a new size, and then emulate a zoom that is set to the pre-defined original scale, and to the right part of the plot.
Meaning, if my X scale is 10 seconds, and I'm rescaling it to 11, I want the displayed plot to start from 1 and the scrollbar to enable scrolling back to 0.
How do I go about this? Also, if there's a better way of doing it, I'd be happy for some pointers.
Optimally I would want to get rid of the UI functionality of the zoomer (the ability to select a zoom rectangle using the mouse) and just use the mechanism for the behind-the-scenes action.
Thanks,
Frankie
Re: Using a zoomer to generate horizontal scrolling without zoom
To clarify: I have the plot copied from the Oscilloscope sample, and the Zoomer classes copied from the Realtime sample.
The changes:
I've removed the Zoomer::rescale implementation calling QwtScaleDraw::setMinimumExtent with the calculated extent (since I wasn't sure how to calculate it with my plot).
Here's MyPlot constructor:
Code:
d_interval(0, 30),
d_paintedPoints(0),
d_timerId(-1)
{
d_directPainter = new QwtPlotDirectPainter();
setAutoReplot(false);
// We don't need the cache here
//canvas()->setPaintAttribute(QwtPlotCanvas::PaintPacked, false);
#if defined(Q_WS_X11)
// Even if not recommended by TrollTech, Qt::WA_PaintOutsidePaintEvent
// works on X11. This has a nice effect on the performance.
canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, true);
canvas()->setAttribute(Qt::WA_PaintOnScreen, true);
#endif
plotLayout()->setAlignCanvasToScales(true);
setAxisTitle
(QwtPlot::xBottom,
"Time [s]");
setAxisTitle
(QwtPlot::yLeft,
"Temperature");
setAxisScale
(QwtPlot::xBottom, d_interval.
minValue(), d_interval.
maxValue());
setAxisScale
(QwtPlot::yLeft,
-20,
20);
grid
->setPen
(QPen(Qt
::gray,
0.0, Qt
::DotLine));
grid->enableX(true);
grid->enableXMin(true);
grid->enableY(true);
grid->enableYMin(false);
grid->attach(this);
/*
// Mark middle
d_origin = new QwtPlotMarker();
d_origin->setLineStyle(QwtPlotMarker::Cross);
// In future calculate middle
d_origin->setValue(5, 0.0);
d_origin->setLinePen(QPen(Qt::gray, 0.0, Qt::DashLine));
d_origin->attach(this);
*/
d_curve
->setPen
(QPen(Qt
::green));
#if 1
d_curve
->setRenderHint
(QwtPlotItem::RenderAntialiased,
true);
#endif
#if 1
d_curve
->setPaintAttribute
(QwtPlotCurve::ClipPolygons,
false);
#endif
d_curve->setData(new CurveData());
d_curve->attach(this);
d_zoomer = new Zoomer(canvas());
d_zoomer
->setRubberBandPen
(QPen(Qt
::red,
2, Qt
::DotLine));
d_zoomer
->setTrackerPen
(QPen(Qt
::red));
}
So assuming my X axis goes from 0 to 30 seconds - what I want to do is Zoom on the area of 1-31 seconds:
1. The scale should grow to 0-31
2. The scrollbar should become visible
3. The plot should be "scrolled" to the rightmost part (meaning I could scroll back to the previous range of 0-30).
I've added a PushButton to "advance" the plot. What it does is:
Code:
// (my y-axis range is -20 to 20)
QRectF newRect
(1,
-20,
30,
40);
m_Plot->setZoomRect(newRect); // This calls: d_zoomer->zoom(newRect);
I've added a Before and After screenshots to show what happens after this code runs.
Before:
http://img816.imageshack.us/img816/9615/zoombefore.png
After:
http://img715.imageshack.us/img715/3390/zoomafter.png
As you can see the horizontal scrollbar appears but it is disabled. Also the canvas has a small offset that wasn't present before.
Re: Using a zoomer to generate horizontal scrolling without zoom
Why don't you simply use a QwtPlotPanner instead of trying to mangle the zoomer code to do the same thing? The panner is designed to move the canvas around without changing the zoom level.
If you need to restrict the panning to one axis only, then you can derive from QwtPlotPanner and reimplement as required. I don't remember exactly which methods need to be changed, but it shouldn't be too hard to figure that out.
Re: Using a zoomer to generate horizontal scrolling without zoom
Quote:
Originally Posted by
frankiefrank
Meaning, if my X scale is 10 seconds, and I'm rescaling it to 11, I want the displayed plot to start from 1 and the scrollbar to enable scrolling back to 0.
It's about connecting a QAbstractSlider or QwtAbstractSlider to QwtPlot::setAxisScale.
This has nothing to do with the ScrollZoomer class from the realtime example - beside, that it also connects a QAbstractSlider ( scroll bar ) with QwtPlot::setAxisScale.
Uwe
Re: Using a zoomer to generate horizontal scrolling without zoom
Thanks for the replies, most of the threads I found on this subject were answered by referring to the realtime example, so I followed that. Now I understand what was the main point (the slider->setaxisscale connection)
Is there an example using the panner?
By the way I managed to correct my original code by calling setZoomBase() after changing the axis scale.