title: Qt mouseMoveEvent only when left mouse button is pressed
body: <p>I currently have a program that draws lines and rectangles. </p>
  
  <pre><code>void mousePressEvent(QMouseEvent *event);
  void mouseReleaseEvent(QMouseEvent *event);
  void mouseMoveEvent(QMouseEvent *event);
  </code></pre>
  
  <p>I use mouseMoveEvent to draw temporary preview of a line and when i release i draw the actual line. What I would like to know is how can i make mouseMoveEvent work work only when i have the left mouse button pressed down. I tried the following but then the whole function stops working.</p>
  
  <pre><code>void mouseMoveEvent(QMouseEvent *event)
  {
       if(event-&gt;button() == Qt::LeftButton)
       {
          //do stuff
       }
  }
  </code></pre>
  
  <p>but then the function doesn't do anything. Any assistance would be much appreciated</p>