Menu

#385 QwtPlotZoomer inaccuracy

open
nobody
None
5
2025-07-16
2025-07-16
Anonymous
No

Hi, I spotted some inconsistency with the coordinates in QwtPlotZoomer. I have a QwtPlot with a bottom and left axes, with an integrated QwtPlotZoomer, which shows a rectangular rubber band and a tracker. The coordinates of the top left corner of the selection, which I see on the tracker are 1 px shifted compared to the coordinates, which are later used for the actual zooming. E.g., if I select a rectangular area with a mouse, moving from the bottom right to the top left corner, after finishing the selection:
in QwtPlotZoomer::widgetMouseReleaseEvent(event), event->pos() == QPoint(74,75),
but QwtPlotZoomer::zoom(rectF), rectF == QRect(75,76 ...)
If a padding is used on the axes and no text fields with current boundaries are given, this 1px actually does not matter much. But if one wants to implement some strickt boundaries, or uses text controls to set/show the limits, it might be annoying, since the text on the tracker does not correspond anymore the final selected area.
I managed to track it down to QwtPlotZoomer::accept() function, where you have this:

QRect rect = QRect( pa.first(), pa.last() );
    rect = rect.normalized();

And in my Qt 6.9.1, this normalize is implemented as:

QRect QRect::normalized() const noexcept
{
    QRect r(*this);
    if (x2 < x1) {                                // swap bad x values
        r.x1 = x2 + 1;
        r.x2 = x1 - 1;
    }
    if (y2 < y1) {                                // swap bad y values
        r.y1 = y2 + 1;
        r.y2 = y1 - 1;
    }
    return r;
}

leading to this +1px shift.

Discussion

Anonymous
Anonymous

Add attachments
Cancel





MongoDB Logo MongoDB