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



  • 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.



  • 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
    }@



  • Yeahhh !!
    Thank you :-)



  • You are welcome. Which solution did you use ?



  • I used the second solution.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.