I have created a line graph using QChartViewCapture.jpg

In this graph, I want to display two squares on top of it, right beside the "Current Hit Ratio" and "Expected Hit Ratio" texts.

For that, I am using QGraphicsItem class to display squares on the QChart. code is given as you follow


<Header>
Qt Code:
  1. class MySqaure : public QGraphicsItem
  2. {
  3. public:
  4. MySqaure();
  5. QRectF boundingRect() const;
  6.  
  7. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
  8. };
To copy to clipboard, switch view to plain text mode 

<Cpp>
Qt Code:
  1. MySqaure::MySqaure()
  2. {
  3.  
  4. }
  5.  
  6. QRectF MySqaure::boundingRect() const
  7. {
  8. return QRectF(0, 0, 100, 100);
  9. }
  10.  
  11. void MySqaure::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
  12. {
  13. QRectF rec = boundingRect();
  14. QBrush brush (Qt::blue);
  15. brush.setColor(Qt::green);
  16.  
  17. painter->fillRect(rec, brush);
  18. painter->drawRect(rec);
  19. }
To copy to clipboard, switch view to plain text mode 

how can I add MySquare to the Qchart view?