Добрый день. Столкнулся с проблемой. при изменения QGraphicsItem остаются следы на QGraphicsScene от старого изображения как от этого избавиться?
QRectF Element::boundingRect() const
{
qreal ymin = 65535;
qreal ymax = 0;
qreal xmin = 65535;
qreal xmax = 0;
foreach (QPointF it, points)
{
if ( it.y() > ymax )
ymax = it.y();
if ( ymin > it.y() )
ymin = it.y();
if ( it.x() > xmax )
xmax = it.x();
if ( xmin > it.x() )
xmin = it.x();
}
return QRectF( QPointF( xmin - 30, ymin - 30 ), QPointF( xmax + 30, ymax + 30 ) );
}
void Element::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED ( option )
Q_UNUSED ( widget )
switch ( elementType )
{
case ElementAngle:
case ElementArrow:
FillPolygon::fillpolygon(painter,points,FillColor);
painter->setPen(QPen(LineColor,2,Qt::SolidLine));
painter->drawPolygon(points.toVector());
if ( selected )
{
painter->setPen(QPen(Qt::red,2,Qt::DotLine));
painter->drawPolygon(points.toVector());
}
switch(transformType)
{
case Spin:
break;
case SPc:
painter->setPen(QPen(Qt::red,2,Qt::DotLine));
painter->drawEllipse( Center,5,5);
break;
case SH:
painter->setPen(QPen(Qt::red,2,Qt::DotLine));
painter->drawLine(horizontal);
break;
case nonTransform:
break;
}
break;
case ElementErmitSpline:
ErmitSpline::drawSqrSpline( painter, points, LineColor, selected );
break;
case ElementNone:
break;
}
}
setFlag(QGraphicsItem::ItemIsMovable, true);
setFlag(QGraphicsItem::ItemIsSelectable, true);
setFlag(QGraphicsItem::ItemIsFocusable, true);
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
надо делать prepareGeometryChange() при изменении геометрии, причём при этом не надо делать update(), всё будет делаться само.
ну или надо делать update() если изменении не приводит к изменению геометрии
Форум Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)