I'm trying to draw a line based on the points selected using the mouse double click event.
Mainwindow is as below:
Qt Code:
  1. class MainWindow : public QMainWindow
  2. {
  3. Q_OBJECT
  4.  
  5. public:
  6. explicit MainWindow(QWidget *parent = 0);
  7. ~MainWindow();
  8.  
  9. private:
  10. Ui::MainWindow *ui;
  11.  
  12. public slots:
  13. void DrawLine(int x1, int y1, int x2, int y2);
  14.  
  15. private slots:
  16. //This method to be used to draw the line after selecting the points.
  17. void on_pushButton_clicked();
  18.  
  19. private:
  20. GraphicsView *view;
  21. QGraphicsPixmapItem *pixmapItem;
  22. QPixmap *pixmap;
  23. };
  24.  
  25. Image is displayed in the mainwindow:
  26.  
  27. view = new GraphicsView();
  28. scene = new QGraphicsScene(0, 0, 800, 600);
  29. pixmapItem = new QGraphicsPixmapItem();
  30. pixmap = new QPixmap(800,600);
  31. QImage img;
  32. img.load("D:/NPOL_Test_Modules/Qt/4.7.1/QGraphicsViewMouseEvent/Winter.jpg"))
  33. QPainter painter;
  34. painter.begin(pixmap);
  35. painter.drawImage(0,0,img);
  36. painter.end();
  37.  
  38. pixmapItem->setPixmap(*pixmap);
  39. scene->addItem(pixmapItem);
  40. view->setScene(scene);
  41.  
  42. connect(view, SIGNAL(PointSelected(int,int,int,int)), this, SLOT(DrawLine(int,int,int,int)));
To copy to clipboard, switch view to plain text mode 

GraphicsView is implemented as below:

Qt Code:
  1. class GraphicsView: public QGraphicsView
  2. {
  3. Q_OBJECT
  4.  
  5. public:
  6. explicit GraphicsView();
  7.  
  8. protected:
  9. void mouseDoubleClickEvent(QMouseEvent *event);
  10.  
  11. signals:
  12. void PointSelected(int a, int b, int c, int d);
  13.  
  14. private:
  15. int x1, y1, x2, y2;
  16. };
  17.  
  18. mouseDoubleClickEvent is as below
  19.  
  20. static int pCount = 0;
  21. if(event->type() == QMouseEvent::MouseButtonDblClick)
  22. {
  23. event->accept();
  24. pCount++;
  25. if(pCount == 1)
  26. {
  27. x1 = QCursor::pos().x();
  28. y1 = QCursor::pos().y();
  29. }
  30. else if(pCount == 2)
  31. {
  32. pCount = 0;
  33. x2 = QCursor::pos().x();
  34. y2 = QCursor::pos().y();
  35. emit PointSelected(x1, y1, x2, y2);
  36. }
  37. }
To copy to clipboard, switch view to plain text mode 

I'm not able to drawline... I have tried using QPainter as below in the DrawLine function of Mainwindow.

Qt Code:
  1. QPainter painter;
  2. painter.begin(pixmap);
  3. painter.drawLine(x1, y1, x2, y2);
  4. painter.end();
To copy to clipboard, switch view to plain text mode 

Please let me know if my approach is right.
My intension is to draw the line on the image once points are selected using the mouse event.
I'll be thankfull if any one can please guide on how I can achieve this.