Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-20300

Bounding rectangle for the image element is wrong if fill mode is PreserveAspectCrop

    XMLWordPrintable

Details

    • 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

        Activity

          People

            bodson Yann Bodson (Inactive)
            bubke Marco Bubke
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes