QGraphicsView unprecise painting with raster engine
I have a QGraphicsView with multiple QGraphicsItems. The items draw a QPixmap into the boundingRect of the item and a black line on the border of the boundingRect. If I use the opengl painting engine the border is exactly where the image is painted. With raster engine there is (depending on the size of the graphics item) space between the drawn border and the drawn image. It looks like the sizes are calculated as integers and not as floats. Is there an option to set or a workaround for this painting errors ?
Are you zooming the viewport and what is the pen width you're using for the rectangle? Are you moving the item or is it static? Can you give an example?
I'am zooming the viewport and the drawn rect should be drawn everytime with the same width in every zoom level. This item can be moved and resized, the inaccurate painting is only done in some zoom - size relations.
// draw the pixmap
painter->setPen(QPen(Qt::black, 1.0, Qt::DashLine));
// reset the transformation
// get the rect to draw without transformation
QPolygonF selectedPolygon = t.map(selectedRect);
// draw some other untransformed stuff
I thought it is some kind of rounding problem, but with opengl it is exactly this code and it works.
This is how it looks
I have seen this problem too. You're using size 1.0 pen width, but zooming the viewport scales this too. If one pixel border line is ok, try using 0.0 pen.
Thank you ! I think I have an error where the selectionRect is calculated.
Hmm the selectionRect is correctly calculated. It must have to do something with pixmap drawing.
Another thing is that the small rect with the white border is drawn like
painter->setPen(QPen(Qt::white, 0.0, Qt::SolidLine));
as you can see it isn't drawn exactly, too.
I have a workaround for raster engine drawing of black rect with a small white border and deactivated Antialiasing.
qreal borderWidth = 1.0;
painter->drawRects(rect.adjusted(borderWidth, borderWidth, -borderWidth, -borderWidth));
Did you try your original code with 0.0 pen and antialiasing disabled?
Atialiasing is false and I tried it with 0.0 and 1.0 pen width and it made no difference because the transformation is reseted.