Unadjusted bouding box with setCosmetic(true)
I want to display "basic" segments in a QGraphicsView with fixed width for the segments, zoom in/out feature and efficient bouding boxes.
The zoom is implemented that way:
Code:
vMatrix.scale(HorizontalScale(), VerticalScale());
setMatrix(vMatrix);
scene()->update();
And the segment that way:
Code:
qreal mX1;
qreal mY1;
qreal mX2;
qreal mY2;
vPen.setCosmetic(true);
vPen.setWidth(3);
aPainter->setPen(vPen);
aPainter->drawLine(mX1, mY1, mX2, mY2);
}
qreal vHalfWidth = sPen.width() / 2.0f;
qreal vX = qMin(mX1, mX2) - vHalfWidth;
qreal vY = qMin(mY1, mY2) - vHalfWidth;
qreal vWidth = qAbs(mX2 - mX1) + vHalfWidth*2;
qreal vHeight = qAbs(mY2 - mY1) + vHalfWidth*2;
return QRectF(vX, vY, vWidth, vHeight
);
}
}
With the code above and an horizontal segment. The bouding box height is always returned to 3. But when zoomin, the segment always has its 3 pixels width (thanks to setCosmetic(true)) BUT the bounding box is stretched larger than the segment drawing.
Any idea on how to handle this ?