Image - apply rotation on condition

  • Hello guys, please help me!

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

    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?

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

  • Yes, that works! Thanks a lot :)

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

Log in to reply

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