Talei
25th March 2014, 01:12
Hello,
What I want to do is to scale and rotate + translate object but I do have problem with scale + rotate.
I have item (QGraphicsPathItem, I do setPath to QRect...), item is square i.e. 100x100, and I do scale item with:
- translate to topLeft boundingBox point
- scale
- translate (back) to -topLeft boundingBox point
QTransform scale= transform();
scale.translate( boundingRect().topLeft().x(), boundingRect().topLeft().y());
scale..scale(2, 4);
scale.translate( -boundingRect().topLeft().x(), -boundingRect().topLeft().y());
so now square is rectangle.
Now I want to rotate that rectangle, so I do:
- translate to center boundingBox point
- rotate
- translate (back) to -center boundingBox point
QTransform rot= transform();
rot.translate( boundingRect().center().x(), boundingRect().center().y());
rot.rotate( angle);
rot.translate( -boundingRect().center().x(), -boundingRect().center().y());
What I would expect to happen is that rectangle will rotate by angle around boundingBox center point.
But what I do got is that path that is painted is painted inside on boundingBox and that bounding box is not rotated.
When I do debug transformation type on paint() event I do see TxShare and I think that I should see TxRotate (top of type enum, so translate + scale + rotate).
I did attached screens of what I go get when I do rotate scaled item and what I want to get.
From left: oryginal -> scaled -> +rotated -> +rotated -> +rotated. Rotation in the same direction.
10165
So to me it seams like order of transform is changed, it should be translate -> scale -> rotate and from screen it seams like it's translate -> rotate -> scale. Or maybe it's translate -> scale -> rotate -> shear but i didn't set shear.
Thanks for any help.
What I want to do is to scale and rotate + translate object but I do have problem with scale + rotate.
I have item (QGraphicsPathItem, I do setPath to QRect...), item is square i.e. 100x100, and I do scale item with:
- translate to topLeft boundingBox point
- scale
- translate (back) to -topLeft boundingBox point
QTransform scale= transform();
scale.translate( boundingRect().topLeft().x(), boundingRect().topLeft().y());
scale..scale(2, 4);
scale.translate( -boundingRect().topLeft().x(), -boundingRect().topLeft().y());
so now square is rectangle.
Now I want to rotate that rectangle, so I do:
- translate to center boundingBox point
- rotate
- translate (back) to -center boundingBox point
QTransform rot= transform();
rot.translate( boundingRect().center().x(), boundingRect().center().y());
rot.rotate( angle);
rot.translate( -boundingRect().center().x(), -boundingRect().center().y());
What I would expect to happen is that rectangle will rotate by angle around boundingBox center point.
But what I do got is that path that is painted is painted inside on boundingBox and that bounding box is not rotated.
When I do debug transformation type on paint() event I do see TxShare and I think that I should see TxRotate (top of type enum, so translate + scale + rotate).
I did attached screens of what I go get when I do rotate scaled item and what I want to get.
From left: oryginal -> scaled -> +rotated -> +rotated -> +rotated. Rotation in the same direction.
10165
So to me it seams like order of transform is changed, it should be translate -> scale -> rotate and from screen it seams like it's translate -> rotate -> scale. Or maybe it's translate -> scale -> rotate -> shear but i didn't set shear.
Thanks for any help.