Sunday, July 20th 2008, 2:24am UTC+1

You are not logged in.

  • Login
  • Register

1

Sunday, May 11th 2008, 5:38pm

item local coordinate

How can i mantain the (0,0) local coordinate in the centre of my QgraphicsRectitem, after a resize?

I use this code for resizing:

Source code

1
2
3
4
5
6
void bottom_resize(){
      QRectF r=rect();
      r.setBottom(event->pos().y());
      setRect(r);
      scene()->update();
      }
  • Go to the top of the page

2

Sunday, May 11th 2008, 6:30pm

RE: item local coordinate

I don't exactly understand

is void bottom_resize() a member of a class? if yes, of which class

what do you want to do, and what do you want to happen?
Nicolas
  • Go to the top of the page

3

Sunday, May 11th 2008, 6:37pm

RE: item local coordinate

I resize my custom QGraphicsRectItem using the function setRect(), how i describe before.

Before resizing, the item centre coordinate is (0,0).....after resizing it changes......

How can i mantain the (0,0) local coordinate in the centre of my item???
  • Go to the top of the page

4

Sunday, May 11th 2008, 7:47pm

RE: item local coordinate

what do you call th "item centre coordinate"?

what is event related to?

...

try something like:
I press mouse button on the bottom edge of the drawn rectangle and drag
I wtant the the drawn rectangle to be resized his bottom edge following the mouse
and the (0,0) point of the QGraphicsRectItem to be always at the center of the drawn rectangle
Nicolas
  • Go to the top of the page

5

Sunday, May 11th 2008, 9:04pm

RE: item local coordinate

I know that there are 3 different kind of coordinate system.
The scene coordinate
The view coordinate
The item coordinate

The (0,0) item coordinate, can correspond to the topleft corner or the centre ...etc...

For example, if i add a QGraphicsRectItem in this mode:

Source code

1
2
3
QRectF area(0,0,50,50);
item = new QGraphicsRectItem(area);
serPos(mouseEvent->scenePos());


i obtain a rect in my scene that has the (0,0) local coordinate in the topleft corner.

If a write:

Source code

1
2
3
QRectF area(-25,-25,50,50);
item = new QGraphicsRectItem(area);
serPos(mouseEvent->mouseEvent->scenePos());


I obtain a rect in my scene that has the (0,0) local coordinate in the centre.

When i resize it, the (0,0) local coordinate changes.
How can i restore the item centre coordinate????

The problem comes if a try ti rotate an item after that i resize it:

Source code

1
setTransform(QTransform().rotate(newrotation));


This rotation is made around the (0,0) item coordinate.......and if this change, i don't obtain the right behaviour.

This post has been edited 1 times, last edit by "dreamer" (May 11th 2008, 9:05pm)

  • Go to the top of the page

6

Monday, May 12th 2008, 10:44am

RE: item local coordinate

test this
Nicolas SOUCHON has attached the following file:
  • main.cpp (4.47 kB - 5 times downloaded - Last download: Jun 21st 2008, 2:40pm)
Nicolas
  • Go to the top of the page

Rate this thread