title: Mouse tracking in Qt
body: <p>I am implementing a code in which when I push the line button, I can track the points to get a line. But for again tracking a line a line I need to push the button again. I want until Esc key is pressed the same signal must remain activated. I don't want to push the button again and again. The code snippet is:
  mainwindow.cpp</p>
  
  <pre><code>    connect(ui-&gt;lineButton, SIGNAL(clicked()),this, SLOT(drawLine()));
  void MainWindow::drawLine(){
  
      ui-&gt;graphicsView-&gt;setScene(scene);
      line *item = new line;
      scene-&gt;addItem(item);
      //connect(item,SIGNAL(drawFinished()),SLOT(drawLine()));
  
      qDebug() &lt;&lt; "Line Created";
  
  
  }
  </code></pre>
  
  <p>line.cpp</p>
  
  <pre><code>    void line::mousePressEvent(QGraphicsSceneMouseEvent* e){
         if(e-&gt;button()==Qt::LeftButton) {
             if(mFirstClick){
                 x1 = e-&gt;pos().x();
                 y1 = e-&gt;pos().y();
                 mFirstClick = false;
                 mSecondClick = true;
             }
  
             else if(!mFirstClick &amp;&amp; mSecondClick){
                 x2 = e-&gt;pos().x();
                 y2 = e-&gt;pos().y();
                 mPaintFlag = true;
                 mSecondClick = false;
                 update();
  
             }
         }
         QGraphicsItem::mousePressEvent(e);
         update();
  
     }
  </code></pre>