diff --git a/lib/documentview/documentview.cpp b/lib/documentview/documentview.cpp --- a/lib/documentview/documentview.cpp +++ b/lib/documentview/documentview.cpp @@ -643,12 +643,16 @@ // Selection indicator/highlight if (d->mCompareMode && d->mCurrent) { - QRectF visibleRect = mapRectFromItem(d->mAdapter->widget(), d->mAdapter->visibleDocumentRect()); painter->save(); painter->setBrush(Qt::NoBrush); painter->setPen(QPen(palette().highlight().color(), 2)); painter->setRenderHint(QPainter::Antialiasing); - QRectF selectionRect = visibleRect.adjusted(-2, -2, 2, 2); + const QRectF visibleRectF = mapRectFromItem(d->mAdapter->widget(), d->mAdapter->visibleDocumentRect()); + // Round the point and size independently. This is different than calling toRect(), + // and is necessary to keep consistent rects, otherwise the selection rect can be + // drawn 1 pixel too big or small. + const QRect visibleRect = QRect(visibleRectF.topLeft().toPoint(), visibleRectF.size().toSize()); + const QRect selectionRect = visibleRect.adjusted(-1, -1, 1, 1); painter->drawRoundedRect(selectionRect, 3, 3); painter->restore(); } diff --git a/lib/documentview/rasterimageview.cpp b/lib/documentview/rasterimageview.cpp --- a/lib/documentview/rasterimageview.cpp +++ b/lib/documentview/rasterimageview.cpp @@ -409,10 +409,11 @@ // In zoomToFit mode, scale crudely the buffer to fit the screen. This // provide an approximate rendered which will be replaced when the scheduled // proper scale is ready. - QSizeF size = documentSize() * zoom(); - painter->drawPixmap(topLeft.x(), topLeft.y(), size.width(), size.height(), d->mCurrentBuffer); + // Round point and size independently, to keep consistency with the below (non zoomToFit) painting + const QRect rect = QRect(topLeft.toPoint(), (documentSize() * zoom()).toSize()); + painter->drawPixmap(rect, d->mCurrentBuffer); } else { - painter->drawPixmap(topLeft, d->mCurrentBuffer); + painter->drawPixmap(topLeft.toPoint(), d->mCurrentBuffer); } if (d->mTool) { diff --git a/lib/documentview/svgviewadapter.cpp b/lib/documentview/svgviewadapter.cpp --- a/lib/documentview/svgviewadapter.cpp +++ b/lib/documentview/svgviewadapter.cpp @@ -49,6 +49,10 @@ , mAlphaBackgroundColor(Qt::black) , mImageFullyLoaded(false) { + // At certain scales, the SVG can render outside its own bounds up to 1 pixel + // This clips it so it isn't drawn outside the background or over the selection rect + mSvgItem->setFlag(ItemClipsToShape); + // So we aren't unnecessarily drawing the background for every paint() setCacheMode(QGraphicsItem::DeviceCoordinateCache); } @@ -101,7 +105,7 @@ void SvgImageView::adjustItemPos() { - mSvgItem->setPos(imageOffset() - scrollPos()); + mSvgItem->setPos((imageOffset() - scrollPos()).toPoint()); update(); } @@ -119,7 +123,8 @@ void SvgImageView::drawAlphaBackground(QPainter* painter) { - const QRectF imageRect = QRectF(imageOffset(), visibleImageSize()); + // The point and size must be rounded to integers independently, to keep consistency with RasterImageView + const QRect imageRect = QRect(imageOffset().toPoint(), visibleImageSize().toSize()); switch (mAlphaBackgroundMode) { case AbstractImageView::AlphaBackgroundNone: