PDA

View Full Version : QGraphicsView update/paint issues



emanuel
21st July 2012, 01:26
Hi,

I have trouble with QGraphicsView update.

Screenshot:

8027

Code:

8028

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:




void AssociItem::Line::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);

painter->setPen(pen());

setLine(QLineF(start->mapToScene(start->boundingRect().center()),
end->mapToScene(end->boundingRect().center())));

QPointF endPoint;

QPolygonF polygon = QPolygonF(end->boundingRect());
QPointF p1 = polygon.first() + end->pos();
QPointF p2;
QLineF polyLine;

int count = polygon.count();
for(int i = 1; i < count; ++i)
{
p2 = polygon[i] + end->pos();
polyLine = QLineF(p1, p2);
QLineF::IntersectType intersectType = polyLine.intersect(line(), &endPoint);
if(intersectType == QLineF::BoundedIntersection)
break;

p1 = p2;
}

QGraphicsTextItem *text = static_cast<AssociItem *>(parentItem())->leftText;
text->setPos(endPoint);

QPointF startPoint;

polygon = QPolygonF(start->boundingRect());
p1 = polygon.first() + start->pos();

count = polygon.count();
for(int i = 1; i < count; ++i)
{
p2 = polygon[i] + start->pos();
polyLine = QLineF(p1, p2);
QLineF::IntersectType intersectType = polyLine.intersect(line(), &startPoint);
if(intersectType == QLineF::BoundedIntersection)
break;

p1 = p2;
}

text = static_cast<AssociItem *>(parentItem())->rightText;
text->setPos(startPoint);

setLine(QLineF(startPoint, endPoint));

painter->drawLine(line());
}



Any ideas?

wysota
21st July 2012, 01:46
paint() is supposed to paint the item inside the area specified by boundingRect(). Nothing more and certainly should not modify the object state.