Hi,

I have trouble with QGraphicsView update.

Screenshot:

image1.jpg

Code:

GraphicsViewExample.tar.bz2

I belive there is a problem with AssociItem :: Line :: paint() where I'm setting position of QGraphicsTextItem, but I have no clue how to fix it:

Qt Code:
  1. void AssociItem::Line::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
  2. {
  3. Q_UNUSED(option);
  4. Q_UNUSED(widget);
  5.  
  6. painter->setPen(pen());
  7.  
  8. setLine(QLineF(start->mapToScene(start->boundingRect().center()),
  9. end->mapToScene(end->boundingRect().center())));
  10.  
  11. QPointF endPoint;
  12.  
  13. QPolygonF polygon = QPolygonF(end->boundingRect());
  14. QPointF p1 = polygon.first() + end->pos();
  15. QPointF p2;
  16. QLineF polyLine;
  17.  
  18. int count = polygon.count();
  19. for(int i = 1; i < count; ++i)
  20. {
  21. p2 = polygon[i] + end->pos();
  22. polyLine = QLineF(p1, p2);
  23. QLineF::IntersectType intersectType = polyLine.intersect(line(), &endPoint);
  24. if(intersectType == QLineF::BoundedIntersection)
  25. break;
  26.  
  27. p1 = p2;
  28. }
  29.  
  30. QGraphicsTextItem *text = static_cast<AssociItem *>(parentItem())->leftText;
  31. text->setPos(endPoint);
  32.  
  33. QPointF startPoint;
  34.  
  35. polygon = QPolygonF(start->boundingRect());
  36. p1 = polygon.first() + start->pos();
  37.  
  38. count = polygon.count();
  39. for(int i = 1; i < count; ++i)
  40. {
  41. p2 = polygon[i] + start->pos();
  42. polyLine = QLineF(p1, p2);
  43. QLineF::IntersectType intersectType = polyLine.intersect(line(), &startPoint);
  44. if(intersectType == QLineF::BoundedIntersection)
  45. break;
  46.  
  47. p1 = p2;
  48. }
  49.  
  50. text = static_cast<AssociItem *>(parentItem())->rightText;
  51. text->setPos(startPoint);
  52.  
  53. setLine(QLineF(startPoint, endPoint));
  54.  
  55. painter->drawLine(line());
  56. }
To copy to clipboard, switch view to plain text mode 

Any ideas?