Even if a QwtPlotRescaler has been installed and activated (using mode Fixed, Expanding or Fitting) the QwtScaleMap given to QwtPlotItem::draw() does not have exactly the same scale for X and Y.
This issue can be illustrated with the playground/rescaler example.
In RectItem::draw(), the call QRectF rect = QwtScaleMap::transform( xMap, yMap, d_rect ); does not return a square even if d_rect is a square.
If we resize the window of this example, we can observe that the error increases with an
increasing ratio for canvas.width() / canvas.height().
I propose the following version of RectItem::draw() to directly display the ratio in the plot item:
virtual void draw( QPainter *painter,
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
const QRectF & ) const
{
if ( d_rect.isValid() )
{
const double x_scale = qAbs((xMap.p2()-xMap.p1()) / (xMap.s2()-xMap.s1()));
const double y_scale = qAbs((yMap.p2()-yMap.p1()) / (yMap.s2()-yMap.s1()));
const QRectF rect = QwtScaleMap::transform(
xMap, yMap, d_rect );
const QString text = QString("%1 %2\n%3\n%4 %5")
.arg(d_rect.width()).arg(d_rect.height()).arg(y_scale / x_scale)
.arg(rect.width()).arg(rect.height());
painter->setPen( d_pen );
painter->setBrush( d_brush );
if ( d_type == Ellipse )
QwtPainter::drawEllipse( painter, rect );
else
QwtPainter::drawRect( painter, rect );
QwtPainter::drawText(painter, rect, Qt::AlignCenter, text);
}
}
In my own project, my PlotItem::draw() implementation relies on a ratio equal to 1 to correctly display a not distorted rotated rectangle.
Anonymous
For information: few more of my users have felt last week in this issue.
I fixed it at least for my own usage, by reimplementing the canvasResizeEvent() method to discard the margins, like this: