PDA

View Full Version : item local coordinate



dreamer
11th May 2008, 14:44
I'd like to have each rect item on the scene, with the local (0,0) coordinate in the centre of the rect.

If i'd like to obtain a rect item with this attribute, a write:


QRectF area(-25,-25,50,50)
myrect = new rectitem(bla,bla,area);
setPos("pos in the scene where i'd like to put my item")


I build the rect in this mode: QRectF area(-width/2,-height/2,width,height);

The problems come, when i resize the rect.
When i resize it, i use the setRect() function, where i set the new rect.
At the end of resize, the local coordinate (0,0) doesn't match with the centre of my item. How can i obtain this behaviour??

dreamer
11th May 2008, 17:12
here my specific code for the vertical resize:


void bottom_resize(){
QRectF r=rect();
r.setBottom(event->pos().y());
setRect(r);
scene()->update();
}


How can I mantein the local coordinate (0,0) on the centre of my resized item???

wysota
11th May 2008, 19:54
Change the boundingRect() implementation. It is the one deciding about coordinates.

dreamer
11th May 2008, 20:52
can i have an example?????

wysota
11th May 2008, 21:40
Sorry, an example of what? Returning of a QRect object?

dreamer
11th May 2008, 21:45
if the code is :



QRectF myItem::boundingRect() const{
return rect();
}


....so i don't resolve the problem.

The item coordinate (0,0) doesn't match with the centre of the item.

wysota
11th May 2008, 22:49
The rect you return has to correspond to the coordinates. If you increase the size of the rectangle and want the (0,0) point to remain in the middle of the rectangle, the upper left corner has to change its coordinates. Otherwise you're just extending the rectangle one way.