PDA

View Full Version : Set EllipseItem center to position



maverick_pol
15th May 2008, 11:52
Hi guys,

I have an ellipeItem( QREctF(0,0,6,6)) set to ignore transformations.
When the user clicks on the scene the item is shown in that place. Using "setPos(qreal,qreal)" sets the position of the item, but its' topLeft bounding rectangle point not the center. I am currently trying to set the items' center to that point.
Sounds simple, but how to achieve this?

THanks.

Kacper

wysota
15th May 2008, 11:56
Return a boundingRect of (-3,-3,6,6).

maverick_pol
15th May 2008, 12:14
Hmm...

Ok. Let's say I have zoomed 100times. The bounding rect is the same(the same width/height), but the coordinates(distance between) changed. AM I right? If yes, the idea above is wrong.

If the item would not ignore the transformations I could use sth like this:


item->boundingRect();
item->setRect(boundingRect.moveCenter(_pos));


And it would work, but the size of the item would change thougt, and I do not want that.
Kacper

maverick_pol
15th May 2008, 12:25
This is a part of my code which I would like to work:


m_originationPoint = m_scene->addEllipse(0,0,6,6);
m_originationPoint->setFlag(QGraphicsItem::ItemIgnoresTransformations) ;
m_originationPoint->setZValue(1);
......
void MyClass::vSetPos(QPointF _pos) {
m_originationPoint->setPos(_pos);// This sets the topLeft boundingRect

}


Thanks for any ideas.

wysota
15th May 2008, 13:03
Simply make the ellipse start from -3, -3 and extend 6 units wide and 6 unit high instead of 0,0 and 6,6. It should all work then - setPos() will set the position of the centre of the ellipse.

maverick_pol
15th May 2008, 13:18
Hi,

Unfortunately, for me, your are totally right. This works.
Why unfortunately? Because I have found a different solution, which was far more complex and I coded it.
Ok...Sorry for the stupid problem.

Kacper