PDA

View Full Version : Resizing a rotated QGraphicsRectItem



Seishin
14th November 2012, 19:58
Hi,
I have a QGraphicsRectItem in my scene with a resize item like this post http://www.qtcentre.org/threads/38654-add-pixels-to-qgraphicsitem#18.
I can rotate and resize the item with mouse dragging.
The problem I met is when I try to resize the rectangle after rotation, the drag direction is in scene coordinate but the resize direction is in the item coordinate.
8415
For example, if I drag the bottom edge in the blue arrow direction, the edge actually moves in the white arrow direction.
Could anyone tell me how to make them consistant? (Dragging to white arrow direction and resizing to white arrow direction.)

This is my resizing code in mouseMoveEvent(), the center of item is (0,0) in the item coordinate:

QPointF pos = event->scenePos()-scenePos();

if(m_selectedItem == 1) // left
rect.setLeft(rectItem, pos.x()/rectItem->scale());
else if(m_selectedItem == 3) // bottom
rect.setBottom(pos.y()/rectItem->scale());
else if(m_selectedItem == 5) // right
rect.setRight(pos.x()/rectItem->scale());
else if(m_selectedItem == 7) // top
rect.setTop(pos.y()/rectItem->scale());

// move the rectangle back to center
QPointF point = rect.center();
rect.moveCenter(QPointF(0, 0));
rectItem->setRect(rect);
rectItem->setPos(rectItem->mapToScene(point));

I tried the function mapToItem() but it seems not work, neither.
Please ignore the extra attachment. I don't know how to remove it.

Seishin
15th November 2012, 16:31
Any Idea on how to map scene or viewport coord to the item coord?