Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [SOLVED] Resize an Image after rotation to fill it's parent
QtWS25 Last Chance

[SOLVED] Resize an Image after rotation to fill it's parent

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 2.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • GianlucaG Offline
    GianlucaG Offline
    Gianluca
    wrote on last edited by
    #1

    Dear all,
    I have this situation:
    @
    Item {
    width: parent.width
    height: parent.height - toolbar.height
    Image {
    anchors.fill: parent
    rotation: gameCtrl.rotation
    fillMode: Image.PreserveAspectFit
    }
    }
    @

    The image can be rotated by 90°-180°-270° degrees.
    The code above fix the dimension of the image respect to dimension of the parent Item (that's rectangular) and does not resize the image when it's rotate to fill all the space available.

    How can I change the code above in order to get the Image resized every time its rotated in order to fill all the space in all possible angles ??
    (I prefer a solution without Quick.Layouts … if exists)

    Thanks.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MaxL
      wrote on last edited by
      #2

      Maybe you could use a state..

      @Image
      {
      id: myImage
      width: parent.width
      height: parent.height
      rotation : gameCtrl.rotation
      fillMode: Image.PreserveAspectFit
      states: State
      {
      when: myImage.rotation == 90 || myImage.rotation == 270
      name: "whatever"
      PropertyChanges
      {
      target: myImage
      width: parent.height
      height: parent.width
      }
      }@

      This should do the trick as well as the following :
      @Image
      {
      id: myImage
      width: ( myImage.rotation == 90 || myImage.rotation == 270 ) ? parent.height : parent.width
      height: ( myImage.rotation == 90 || myImage.rotation == 270 ) ? parent.width : parent.height
      rotation : gameCtrl.rotation
      }@

      1 Reply Last reply
      0
      • GianlucaG Offline
        GianlucaG Offline
        Gianluca
        wrote on last edited by
        #3

        Yeahhh !!
        Thank you :-)

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MaxL
          wrote on last edited by
          #4

          You are welcome. Which solution did you use ?

          1 Reply Last reply
          0
          • GianlucaG Offline
            GianlucaG Offline
            Gianluca
            wrote on last edited by
            #5

            I used the second solution.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved