Vyivrain
6th April 2014, 19:51
Hello , I have a problem, that QGraphicsItem doesn't update, when I'm calling update(). This is what I'm doing:
CircleItem.cpp
void CircleItem::mouseMoveEvent(QGraphicsSceneMouseEven t *event)
{
RectItem->SetBackGround();
QGraphicsItem::mouseMoveEvent( event );
}
RoundRectItem.cpp
void RoundRectItem::SetBackGround()
{
ChangeBackground = true;
update();
}
void RoundRectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QRectF rec = QRectF( QPoint( 0,0 ), boundingRect().size() / 2 );
roundRect = QRectF(rec.adjusted(-rec.height() / 2, 0, rec.height()/2, 0));
roundRect.moveTo( boundingRect().center().x() - roundRect.width() / 2,
boundingRect().center().y() - roundRect.height() / 2 );
if( !ChangeBackground )
painter->setBrush( backBrush );
else
painter->setBrush( QBrush( Qt::blue ) );
painter->setPen( QColor( 255,255,255 ) );
painter->drawRoundedRect(roundRect, roundRect.height() / 2, roundRect.height() / 2 );
}
And after this, roundrect doesn't update its background.
CircleItem.cpp
void CircleItem::mouseMoveEvent(QGraphicsSceneMouseEven t *event)
{
RectItem->SetBackGround();
QGraphicsItem::mouseMoveEvent( event );
}
RoundRectItem.cpp
void RoundRectItem::SetBackGround()
{
ChangeBackground = true;
update();
}
void RoundRectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QRectF rec = QRectF( QPoint( 0,0 ), boundingRect().size() / 2 );
roundRect = QRectF(rec.adjusted(-rec.height() / 2, 0, rec.height()/2, 0));
roundRect.moveTo( boundingRect().center().x() - roundRect.width() / 2,
boundingRect().center().y() - roundRect.height() / 2 );
if( !ChangeBackground )
painter->setBrush( backBrush );
else
painter->setBrush( QBrush( Qt::blue ) );
painter->setPen( QColor( 255,255,255 ) );
painter->drawRoundedRect(roundRect, roundRect.height() / 2, roundRect.height() / 2 );
}
And after this, roundrect doesn't update its background.