You can use any math calculations you want. The shape doesn't matter. Remember you always have the boundingRect() you can work with.
You can use any math calculations you want. The shape doesn't matter. Remember you always have the boundingRect() you can work with.
Hi again,
But if we can only play with the bounding rectangle, how can we perform this movement on a polygon since the bounding rectangle always returns a QRectF?
I will be pleased if you can give me more tips about it.
Thanks in advance
Sorry for the late answer first,
Yes I can. First of all, think I have a polygonal path for the mouse to be moved on the view. Then please see the following shape I've sent.
In this shape 1,2 and 3 are the example valid mouse locations. Suppose that the white background is the view(or scene) and the polygonal path is the path that the mouse can only move on.
Last edited by zgulser; 6th July 2009 at 13:48.
I really don't see what is so problematic. Did you try using itemChange() as I told you? You can check there if the new position of the item is on the polyline and if not, snap it to the desired position. The fact that the example uses a rectangular area doesn't mean you can only snap to rectangular areas.
Hi again,
I'm of course using itemChange method. But the problematic case is about the snapping. I couldn't figure out how to snap actually. That's why I said I need a closest point to my polygonal path to snap in one of my previous posts in this thread. What should I do in order to catch the correct snap position when the mouse moves?
Either do maths manually (the formula is not complicated) and/or use what QLineF offers. In general you need to find a line that is perpendicular to the closest component of the polyline that goes through the point of the current position of the item and then find the intersection of the original line and the perpendicular and the result will be the desired position of the item.
Of course you can just cheat and find two points - one that has the same horizontal coordinate as the current point and lies on the desired line, the other that has the same vertical coordinate as the current point and lies on the desired line and then compare the points to the current point and pick the one that is closer to the current point as the new point of the item.
You will still need to detect which component of the polyline is the closest to the current point.
Edit: here is a diagram to illustrate
Last edited by wysota; 6th July 2009 at 15:09.
zgulser (7th July 2009)
Bookmarks