PDA

View Full Version : QGraphicsItem move only on certain condition



pratham_shah
29th April 2013, 08:17
I have an application (consider something like paint) where in I create custom QGraphicsItem ( assume something similar to a rectangle for understanding the problem). There is a functionality where in the user can resize the QGraphicsItem, but the item must maintain some aspect ratio. (i.e. for eg. the height of the rectangle cannot be greater than half its width).

For resizing I create 4 QGraphicsItem object which are positioned at the four corners. Clicking on the resize rects and dragging the mouse resizes the associated QGraphicsItem.
Now on clicking any resize rects the resizing starts and the size of the QGraphicsItem changes according to the mouse move while maintaining the aspect ratio.
So for the rectangle after the height is equal to half its width the size of the QGraphicsItem doesn't change for any mouse move in vertical direction ( i.e. the height of the QGraphicsItem wont change on dragging the mouse vertically down).

But my problem is that when I move the mouse vertically down after the rectangle has height is equal to half its width the resize rect should still stay at the corner of the QGraphicsItem.
Currently it moves along with the mouse.
Is there any way to achieve it ?

wysota
29th April 2013, 08:22
QGraphicsItem::itemChange()

pratham_shah
29th April 2013, 09:36
Thanks for quick reply.

But I have another problem that how will the resize rect objects know about the aspect ratio being maintained. Maintaining the aspect ratio is the property of the associated QGraphicsItem. So how will the item change know that what position to consider invalid.
If I use the item change of the custom QGraphicsItem and set the resize points position on geometry change would still lead to the same issue.

Maybe will need to change the architecture. Is there any other solution ??

wysota
29th April 2013, 09:54
"Teach" your handle objects about it. Or use itemChange() on the main object.