Details
-
Bug
-
Resolution: Done
-
P2: Important
-
4.8.0, 5.0.0
-
None
-
I8aa84ec64f7be536e56cdc1c04a6c2f204e06c26
Description
If you choose fill mode PreserveAspectCrop the bounding rectangle top left corner is still (0,0) but the painting method is painting left of this point. The QmlDesigner is using the bounding rectangle to compute the painting area and so the preview is wrong. The flowing patch is fixing this problem.
see also QTCREATORBUG-4602
diff --git a/src/declarative/graphicsitems/qdeclarativeimage.cpp b/src/declarative/graphicsitems/qdeclarativeimage.cpp index e6bb798..72b8840 100644 --- a/src/declarative/graphicsitems/qdeclarativeimage.cpp +++ b/src/declarative/graphicsitems/qdeclarativeimage.cpp @@ -443,7 +443,21 @@ void QDeclarativeImage::geometryChanged(const QRectF &newGeometry, const QRectF QRectF QDeclarativeImage::boundingRect() const { Q_D(const QDeclarativeImage); - return QRectF(0, 0, qMax(d->mWidth, d->paintedWidth), qMax(d->mHeight, d->paintedHeight)); + QRectF boundingRect(0, 0, qMax(d->mWidth, d->paintedWidth), qMax(d->mHeight, d->paintedHeight)); + + if (d->fillMode == PreserveAspectCrop) { + qreal widthScale = width() / qreal(d->pix.width()); + qreal heightScale = height() / qreal(d->pix.height()); + if (widthScale < heightScale) { + widthScale = heightScale; + boundingRect.moveTo((width() - widthScale * d->pix.width()) / 2, 0); + } else if(heightScale < widthScale) { + heightScale = widthScale; + boundingRect.moveTo(0, (height() - heightScale * d->pix.height()) / 2); + } + } + + return boundingRect; } /*!
Attachments
For Gerrit Dashboard: QTBUG-20300 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
1859,4 | Bounding rectangle for image is wrong for PreserveAspectCrop | master | qt/qtdeclarative | Status: MERGED | +2 | 0 |