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

Using Image.PreserveAspectFit results in inconsistent implicit/source size

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 4.7.3, 6.5.0 RC
    • None

    Description

      Run the code below, and click on the screen twice:

      import QtQuick 1.1
      
      Item {
          width: 640
          height: 480
      
          MouseArea {
              property bool clicedOnce: false
              anchors.fill: parent
              onClicked: {
                  print("BEFORE")
                  print("\timplicitWidth: " + image.implicitWidth + " (sourceSize.width is " + image.sourceSize.width + ")")
                  print("\timplicitHeight: " + image.implicitHeight + " (sourceSize.height is " + image.sourceSize.height + ")")
      
                  if(!clicedOnce) {
                      print("Setting image width")
                      image.width = image.implicitWidth/2;
                  }
                  else {
                      print("Setting image height")
                      image.height = image.implicitHeight/2;
                  }
      
                  clicedOnce = true;
      
                  print("AFTER")
                  print("\timplicitWidth: " + image.implicitWidth + " (sourceSize.width is " + image.sourceSize.width + ")")
                  print("\timplicitHeight: " + image.implicitHeight + " (sourceSize.height is " + image.sourceSize.height + ")")
                  print("")
      
              }
          }
      
          Image {
              id: image
      
              source: "stretchbench/images/testIcon.png"
              fillMode: Image.PreserveAspectFit
          }
      }
      

      This results in the following output in the console:

      BEFORE
      	implicitWidth: 49 (sourceSize.width is 49)
      	implicitHeight: 57 (sourceSize.height is 57)
      Setting image width
      AFTER
      	implicitWidth: 49 (sourceSize.width is 49)
      	implicitHeight: 28.5 (sourceSize.height is 28)
      
      BEFORE
      	implicitWidth: 49 (sourceSize.width is 49)
      	implicitHeight: 28.5 (sourceSize.height is 28)
      Setting image height
      AFTER
      	implicitWidth: 49 (sourceSize.width is 49)
      	implicitHeight: 28.5 (sourceSize.height is 28)
      

      This seems wrong.

      The correct output should be:

      BEFORE
      	implicitWidth: 49 (sourceSize.width is 49)
      	implicitHeight: 57 (sourceSize.height is 57)
      Setting image width
      AFTER
      	implicitWidth: 24.5 (sourceSize.width is 49)
      	implicitHeight: 28.5 (sourceSize.height is 57)
      
      BEFORE
      	implicitWidth: 24.5 (sourceSize.width is 49)
      	implicitHeight: 28.5 (sourceSize.height is 57)
      Setting image height
      AFTER
      	implicitWidth: 12.25 (sourceSize.width is 49)
      	implicitHeight: 14.25 (sourceSize.height is 57)
      

      Attachments

        Issue Links

          For Gerrit Dashboard: QTBUG-17269
          # Subject Branch Project Status CR V

          Activity

            People

              qt.team.quick.subscriptions Qt Quick and Widgets Team
              mathiasm Mathias Malmqvist
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There is 1 open Gerrit change