I have following problem:
I have a BallItem class derived from QGraphicsItem.
When I update position of my BallItem, Ballitem is flickering and sometimes in the screen (QGraphicsView) there are some remains left.

I attach source code of overrode methods:

Qt Code:
  1. BallItem::BallItem(qreal aPosX, qreal aPosY, qreal aRadius,QGraphicsItem *aParent) :
  2. QGraphicsItem(aParent),
  3. iVx(0),iVy(0),iRadius(aRadius)
  4. {
  5. setPos(aPosX,aPosY);
  6. }
  7.  
  8.  
  9. QRectF BallItem::boundingRect() const
  10. {
  11. qreal adjust = 0.5;
  12. QRectF rectf = QRectF(-iRadius-adjust,-iRadius-adjust,iRadius*2 + adjust
  13. ,iRadius*2 + adjust);
  14. return rectf;
  15. }
  16.  
  17.  
  18. void BallItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
  19. QWidget *widget)
  20. {
  21. painter->save();
  22.  
  23. painter->setBrush(Qt::red);
  24. painter->drawEllipse(QPointF(0,0),iRadius,iRadius);
  25.  
  26. painter->restore();
  27. }
To copy to clipboard, switch view to plain text mode 

Here I initialise QGraphicsView(iGameView) and QGraphicsScene(iGameScene)

Qt Code:
  1. iGameView->setRenderHint(QPainter::Antialiasing);
  2. iGameView->setCacheMode(QGraphicsView::CacheBackground);
  3. iGameView->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
  4. iGameView->setBackgroundBrush(Qt::green);
  5. iGameView->setAttribute(Qt::WA_LockPortraitOrientation, true);
  6.  
  7. iGameScene->setItemIndexMethod(QGraphicsScene::NoIndex);
  8.  
  9. iGameView->setScene(iGameScene);
To copy to clipboard, switch view to plain text mode 

I make position updates in advance method.
Qt Code:
  1. void BallItem::advance(int phase)
  2. {
  3. if (!phase)
  4. return;
  5.  
  6. bool flipX = false;
  7. bool flipY = false;
  8.  
  9. qreal newX = x();
  10. qreal newY = y();
  11.  
  12. if (newX + iRadius + iVx > scene()->width())
  13. {
  14. newX = scene()->width() - iRadius;
  15. flipX = true;
  16. }
  17. else if (newX - iRadius +iVx < 0)
  18. {
  19. newX = iRadius;
  20. flipX = true;
  21. }
  22. else
  23. newX+=iVx;
  24.  
  25. if (newY + iRadius + iVy > scene()->height())
  26. {
  27. newY = scene()->height() - iRadius;
  28. flipY = true;
  29. }
  30. else if (newY - iRadius + iVy < 0)
  31. {
  32. newY = iRadius;
  33. flipY = true;
  34. }
  35. else
  36. newY+=iVy;
  37.  
  38. setPos(newX,newY);
  39.  
  40. if (flipX)
  41. iVx = -iVx;
  42.  
  43. if (flipY)
  44. iVy = -iVy;
  45.  
  46. }
To copy to clipboard, switch view to plain text mode 

I am sorry for attaching so much source code but I know that there are some issues about mapping from item coordinate system to scene coordinate system and maybe I do something wrong in presented source code. Something what will be caught by more experienced eye.