PDA

View Full Version : QGraphicsEllipseItem: ItemSendsScenePositionChanges move event?



harakiri
24th September 2010, 16:45
Hi,

i have a 4 vertices:



Vertex::Vertex(int x, int y) : QGraphicsEllipseItem(x-1,y-1,x+1,y+1)
{
QPen currentPen = pen();
currentPen.setColor(Qt::blue);
currentPen.setWidth(3);
setPen(currentPen);
setAcceptsHoverEvents( true );
setFlag( QGraphicsItem::ItemIsMovable, true );
setFlag( QGraphicsItem::ItemSendsScenePositionChanges, true );
}


that describe a polygon (QGraphicsPathItem)
they are added to a QGraphicsScene in a QGraphicsView.

So far, everything's fine; i can move the the vertices around, hover effects and so on are working fine.

But now, i want to adjust the polygon if a user changes a vertex.
Is there any event the QGraphicsEllipseItem emits when moved?
Or does the QGraphicsScene have an event to tell me it's content hast changed?

i am looking for something like:



connect(m_scene, SIGNAL(changed()),
this, SLOT(updatePolygon()));


or



Vertex* vertex = new Vertex(event->x(), event->y());
connect(vertex, SIGNAL(ItemPositionHasChanged()),
this, SLOT(updatePolygon()));


but both didn't work

Lykurg
24th September 2010, 17:08
See QGraphicsItem::itemChange() with QGraphicsItem::ItemPositionChange. If you need signals to inform your scene or whatever inherit QObject. Also not the difference between [QTCLASS] and [CODE].

harakiri
24th September 2010, 17:44
See QGraphicsItem::itemChange() with QGraphicsItem::ItemPositionChange. If you need signals to inform your scene or whatever inherit QObject. Also not the difference between [QTCLASS] and [CODE].



QVariant Vertex::itemChange(GraphicsItemChange change, const QVariant &value)
{
cout << "test" << std::endl;
return QGraphicsItem::itemChange(change, value);
}


itemChange is only called when the vertex is created, not when i move it

Lykurg
24th September 2010, 17:48
Yeah, sometimes you have to read the documentation ;)
This notification is send if the ItemSendsGeometryChanges flag is enabled

harakiri
27th September 2010, 12:28
Yeah, sometimes you have to read the documentation ;)

i did that, but i switched


setFlag( QGraphicsItem::ItemSendsScenePositionChanges, true );


for



setFlag( QGraphicsItem::ItemSendsGeometryChanges, true );


now it's working. thanks