title: Qt 4.7 - Drawing a 2 point line with dynamic feedback using paintEvent
body: <p>so I am trying to draw a line between two points. Left mouse click starts the line then I would like the line to by dynamically drawn as the mouse moves (almost like a preview of the line). Left mouse click again and the line will be permanently drawn. I know there are a lot of other posts about QPaintEvents and I have combined some of the techniques used, but for some reason nothing is being drawn to the canvas. Below is the code:</p>
  
  <pre><code>void Main::mousePressEvent(QMouseEvent * event)
  {
      if (event-&gt;button() == Qt::LeftButton) {
      QPointF pos = event-&gt;pos();
          if( mStartPoint.isNull() ) {
              if(josh.contains(pos))
                  mStartPoint = pos;
          } else {
              canvas.addLine(mStartPoint.x(),mStartPoint.y(),pos.x(),pos.y());
              mStartPoint = QPointF();
          }
      }
  }
  
  bool Main::eventFilter(QObject *obj, QEvent *event)
  {
    if (event-&gt;type() == QEvent::MouseMove)
    {
      QMouseEvent *mouseEvent = static_cast&lt;QMouseEvent*&gt;(event);
      if (!mStartPoint.isNull()) {
          m_targetImage = QImage(canvas.width(),canvas.height(),QImage::Format_ARGB32);
          QPainter p;
          p.begin(&amp;m_targetImage);
          p.drawLine(mStartPoint, mouseEvent-&gt;pos());
          p.end();
      }
      statusBar()-&gt;showMessage(QString("Mouse move (%1,%2)").arg(mouseEvent-&gt;pos().x()).arg(mouseEvent-&gt;pos().y()));
    }
    return false;
  }
  
  void Main::paintEvent(QPaintEvent *pe)
  {
          QPainter painter(this);
          QPen pen(Qt::red);
          pen.setWidth(10);
          painter.setPen(pen);
          painter.drawImage(0, 0, m_targetImage);
  }
  </code></pre>
  
  <p>Any help is appreciated! Thanks! Josh</p>