PDA

View Full Version : Realtime example ScrollZoomer and QwtPlotItem::Margins flag



ars
3rd December 2014, 17:17
Hello,

I'm currently experimenting with the ScrollZoomer class provided by Qwt realtime example. I want to add some margin between the trace and the canvas, so I derived a class PlotCurve from QwtPlotCurve setting the Margins attribute and overriding getCanvasMarginHint():


PlotCurve::PlotCurve(const QString& name)
: QwtPlotCurve(name)
{
setItemAttribute(Margins, true);
setCurveAttribute(Fitted, false);
}

PlotCurve::~PlotCurve()
{
}

void PlotCurve::getCanvasMarginHint(const QwtScaleMap &xMap,
const QwtScaleMap &yMap,
const QRectF &canvasRect,
double &left,
double &top,
double &right,
double &bottom
)const
{
left = 5.0;
right = 0.0;
top = 20;
bottom = 10.0;
}

When creating a trace in the X range [0,100] and starting to zoom into this trace I observed that the axis scales ran into the area occupied by the vertical slider. This has the bad side effect that I cannot zoom around the last trace points.

To check if this also happens with the realtime code, I used the PlotCurve class above also in the realtime example and changed the realtime example X range from 1000 to 100. Moreover I changed the application style to cleanlooks, so that the misalignment is better visible. Here are 2 screenshots. The first one shows the application where everything is ok while the second one shows the failure occurring after the next zoom step.
10780 10781
Going up the zoom stack by 1 (back to the previously state where everything was ok) we observe that it is failing now too:
10782
I even tried setting left, top, right and bottom all to 0. The result is similar. Only when resetting the Margins flag to false in PlotCurve zooming behaves as expected. Note that it also works with a range of 1000 (both in realtime example and my application).

Any ideas how to fix this?

Thanks for any suggestions
ars

Edit 1: Setting top and right in getCanvasMarginHint() to values >= scrollbar extent prevents the scales from running into the scrollbar area.

Uwe
4th December 2014, 08:52
I'm currently experimenting with the ScrollZoomer class provided by Qwt realtime example. I want to add some margin between the trace and the canvas, so I derived a class PlotCurve from QwtPlotCurve setting the Margins attribute and overriding getCanvasMarginHint()
As the scroll zoomer also manipulates the canvas margin this won't work. But using the Margins attribute ( necessary for bar charts, where the bar needs extra space ) is probably not want you want to do.

Instead I guess this is your code:


plot->plotLayout()->setCanvasMargin( ... );You have to do it before the scroll zoomer gets created, as the zoomer modifies the margins by adding/subtracting the scroll bar extent from the current margins.

Uwe

ars
4th December 2014, 14:49
Hello Uwe,

thanks for your reply. It's now working (with some additional changes specific to my application) as I've expected.

Best regards
ars