Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set rotation point of Rectangle

Is there a way to set rotation point in Rectangle and simply use rotation property without any other additional component? I want to rotate a Rectangle with binding property of rotation: value * 180 like this

Rectangle{
    id: body
    rotation: value
    anchors.centerIn: parent.Center
    antialiasing: true
}
onValueChanged: body.rotation = value

I got only rotation around the left upper corner of parent. Please help me to understand this behavior or suggest me another way to implement rotation on the center.

like image 403
user3417815 Avatar asked Dec 03 '25 17:12

user3417815


1 Answers

rotation property rotates item clockwise around its transformOrigin property which could be one of these nine points :

enter image description here

So you can rotate around one of them like :

Rectangle{
    id: body
    rotation: value
    transformOrigin: Item.Center
    anchors.centerIn: parent.Center
    antialiasing: true
}

If you want to rotate around an arbitrary point you should use Rotation transform type :

Rectangle{
    id: body
    transform: Rotation { origin.x: 25; origin.y: 25; angle: value}
    anchors.centerIn: parent.Center
    antialiasing: true
}
like image 153
Nejat Avatar answered Dec 06 '25 09:12

Nejat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!