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:
{
Q_UNUSED(option);
Q_UNUSED(widget);
painter->setPen(pen());
setLine
(QLineF(start
->mapToScene
(start
->boundingRect
().
center()),
end->mapToScene(end->boundingRect().center())));
QPointF p1
= polygon.
first() + end
->pos
();
int count = polygon.count();
for(int i = 1; i < count; ++i)
{
p2 = polygon[i] + end->pos();
QLineF::IntersectType intersectType
= polyLine.
intersect(line
(),
&endPoint
);
if(intersectType
== QLineF::BoundedIntersection) break;
p1 = p2;
}
text->setPos(endPoint);
p1 = polygon.first() + start->pos();
count = polygon.count();
for(int i = 1; i < count; ++i)
{
p2 = polygon[i] + start->pos();
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());
}
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());
}
To copy to clipboard, switch view to plain text mode
Any ideas?
Bookmarks