Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Image - apply rotation on condition

    QML and Qt Quick
    2
    4
    537
    Loading More Posts
    • 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.
    • V
      Vinayak17 last edited by

      Hello guys, please help me!

      I am using Image item type to display one image along with setting the rotation property as below:

      Image
      {
      transform: Rotation {
      origin.x: 0
      origin.y: height / 8
      axis {
      x: 0
      y: 1
      z: 0
      }
      angle: 60
      }
      source: "qrc:/image/abc.png"
      }

      Now I want the rotation to apply only when I am displaying abc.png image whereas I don't want to apply the rotation if I am using xyz.png. How can I achieve this task?

      1 Reply Last reply Reply Quote 1
      • ODБOï
        ODБOï last edited by ODБOï

        Hello @Vinayak17 !

        you can use JS expression like this :

        angle : source == "qrc:/image/abc.png" ? 60 : 0

        Or you can create a function that will return a rotation based on the image name

        function rotationByName(imgSource){
        var rot = 0;
        switch(imgSource){
        case "qrc:/image/abc.png" : rot = 60;break;
        case "qrc:/image/hij.png" : rot = 33;break;
        default : break;
        }
        return rot
        }

        and then use this function :

        rotation : rotationByName(myImg.source)

        I hope this will help you.
        LA

        1 Reply Last reply Reply Quote 2
        • V
          Vinayak17 last edited by

          Yes, that works! Thanks a lot :)

          ODБOï 1 Reply Last reply Reply Quote 1
          • ODБOï
            ODБOï @Vinayak17 last edited by

            @Vinayak17 Perfect ;) you can upVote if you want !
            LA

            1 Reply Last reply Reply Quote 0
            • First post
              Last post