title: Shift key click in qt?
body: <p>I am working on a paint program in QT5 C++ and I am trying to modify a function that draws a line to incorporate the 45 degree, horizontal or vertical special line that should be drawn if the shift key is clicked. </p>
  
  <p>Below is what I have but for some reason the key handler is not working for me. </p>
  
  <p>I received an error but I don't understand what I need to do to fix it attached below is the error and the code for the paint function that I've modified after that. I have wrapped the modification I did in comments for readability</p>
  
  <p><a href="https://i.stack.imgur.com/fkcjD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fkcjD.png" alt="Runtime error"></a></p>
  
  <pre><code>void LineInstrument::paint(ImageArea &amp;imageArea, bool isSecondaryColor, bool)
  {
      QPainter painter(imageArea.getImage());
      if(isSecondaryColor)
      {
          painter.setPen(QPen(DataSingleton::Instance()-&gt;getSecondaryColor(),
                              DataSingleton::Instance()-&gt;getPenSize() * imageArea.getZoomFactor(),
                              Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
      }
      else
      {
          painter.setPen(QPen(DataSingleton::Instance()-&gt;getPrimaryColor(),
                              DataSingleton::Instance()-&gt;getPenSize() * imageArea.getZoomFactor(),
                              Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
      }
  
      if(mStartPoint != mEndPoint) // here is where the line is drawn 
      {
          painter.drawLine(mStartPoint, mEndPoint); // let the line be drawn
          // my modifications start here
          if (QApplication::keyboardModifiers().testFlag(Qt::ShiftModifier) == true) { // check if shift key is active
              QMouseEvent *mouse;
              if (mouse-&gt;pos().x() &gt; mouse-&gt;pos().y()){
                  // transform to a horizontal line
                  painter.save(); // save current painter state
                  painter.rotate(180);
                  painter.restore(); // restores painter state 
  
              }
              else if (mouse-&gt;pos().x() &lt; mouse-&gt;pos().y()){
                  // transfomr to a vertical line 
                  painter.save();
                  painter.rotate(90);
                  painter.restore();
              }
              else{
                  // transform to a 45 degree line
                  painter.save();
                  painter.rotate(45);
                  painter.restore();
              }
          }// and end here
  
      }
  
      if(mStartPoint == mEndPoint)
      {
          painter.drawPoint(mStartPoint);
      }
      imageArea.setEdited(true);
      //    int rad(DataSingleton::Instance()-&gt;getPenSize() + round(sqrt((mStartPoint.x() - mEndPoint.x()) *
      //                                                                 (mStartPoint.x() - mEndPoint.x()) +
      //                                                                 (mStartPoint.y() - mEndPoint.y()) *
      //                                                                 (mStartPoint.y() - mEndPoint.y()))));
      //    mPImageArea-&gt;update(QRect(mStartPoint, mEndPoint).normalized().adjusted(-rad, -rad, +rad, +rad));
      painter.end();
      imageArea.update();
  }
  </code></pre>