You got it almost right, but you have a signature mismatch. The problem is, your "collidesWithItem" is not a re-implementation of the base class method, you just simply introduced a new function to your class. In order to override a method, it needs to have exactly the same signature as in the base class:
Qt Code:
  1. bool QGraphicsItem::collidesWithItem(const QGraphicsItem * other, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
  2. // above signature will work ok, your method:
  3. bool collidesWithItem(const Ball *ball, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
To copy to clipboard, switch view to plain text mode 
Btw. if you are using C++11, you can take advantage of the "override" specifier, for example:
Qt Code:
  1. #ifndef BALL_H
  2. #define BALL_H
  3.  
  4. #include <QGraphicsItem>
  5.  
  6.  
  7. class Ball : public QGraphicsItem
  8. {
  9. public:
  10. Ball();
  11. Ball(double x, double y);
  12. Ball(double x, double y, double angle);
  13. ~Ball();
  14.  
  15. QRectF boundingRect() const override;
  16. QPainterPath shape() const override;
  17. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
  18. QWidget *widget) override;
  19.  
  20. // this should give a compilation error, as the base class does not declare a virtual method with this signature
  21. bool collidesWithItem(const Ball *ball, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const override;
  22.  
  23.  
  24. ...
  25.  
  26. };
  27.  
  28. #endif // BALL_H
To copy to clipboard, switch view to plain text mode