With the mouse I create a polyline. That's the first QGraphicsItem. For every click with the mouse I create a child Item which draws an ellipse on every position I clicked the Mouse. The ellipse is movable and the purpose is to modify the polyline. When I move the ellipse the polyline is modified indeed but not following the ellipse. It has a big offset from the ellipse. What am I missing here?

Parent item:
Qt Code:
  1. itemSpline::itemSpline(QGraphicsItem *parent)
  2. {
  3. // TODO Auto-generated constructor stub
  4. //setAcceptHoverEvents(true);
  5. // setFlags(ItemIsMovable | ItemIsFocusable | QGraphicsItem::ItemIsSelectable);
  6. setFlags(QGraphicsItem::ItemIsSelectable);
  7. setZValue(20.);
  8. myColor = Qt::black;
  9. isFinished = false;
  10. }
  11.  
  12. QVariant itemSpline::itemChange(GraphicsItemChange change, const QVariant &value)
  13. {
  14. if(ItemPositionHasChanged)
  15. {
  16. //Should I do something here?
  17. }
  18. return QGraphicsPolygonItem::itemChange(change, value);
  19. }
  20.  
  21. void itemSpline::alterPolygon(QPointF pos, int index)
  22. {
  23. qDebug("alterPolygon");
  24.  
  25. //Calculate offset and change boundingRectangle?
  26. prepareGeometryChange();
  27. vVertices[index] = pos;
  28. }
To copy to clipboard, switch view to plain text mode 

Child item: (Ellipse)
Qt Code:
  1. Node::Node(QPointF nodePos, itemSpline *parent, int ind)
  2. : QGraphicsItem(parent), splineItem(parent)
  3. {
  4. // TODO Auto-generated constructor stub
  5. newPos = mapToParent(nodePos);
  6.  
  7. index = ind;
  8. setAcceptsHoverEvents(true);
  9. setFlag(ItemIsMovable);
  10. setFlag(ItemSendsGeometryChanges);
  11. setCacheMode(DeviceCoordinateCache);
  12. setZValue(-1);
  13. }
  14.  
  15. QRectF Node::boundingRect() const
  16. {
  17. return QRectF(newPos.x()-4, newPos.y()-4, 8,8);
  18. }
  19.  
  20. //This does nothing?
  21. bool Node::advance()
  22. {
  23. qDebug("Node: Advance");
  24.  
  25. if (newPos == pos())
  26. return false;
  27.  
  28. setPos(newPos);
  29.  
  30. return true;
  31. }
  32.  
  33. QVariant Node::itemChange(GraphicsItemChange change, const QVariant &value)
  34. {
  35. //only if polyline is finished!
  36. if(splineItem->isFinished)
  37. {
  38. if(ItemPositionHasChanged)
  39. {
  40. QPointF valuePos(value.toPointF());
  41.  
  42. splineItem->alterPolygon(mapToParent(valuePos), index);
  43.  
  44. }
  45. }
  46.  
  47. return QGraphicsItem::itemChange(change, value);
  48. }
To copy to clipboard, switch view to plain text mode