title: How to add a arrow head to my line in pyqt4?
body: <p>I got this code:</p>
  
  <pre><code>from PyQt4 import QtGui, QtCore
  
  class MyFrame(QtGui.QGraphicsView):
      def __init__( self, parent = None ):
          super(MyFrame, self).__init__(parent)
  
          scene = QtGui.QGraphicsScene()
          self.setScene(scene)
          self.resize( 400, 240 )
  
          # http://pyqt.sourceforge.net/Docs/PyQt4/qpen.html
          pencil = QtGui.QPen( QtCore.Qt.black, 2)
          pencil.setStyle( QtCore.Qt.SolidLine )
  
          # pencil.setStyle( QtCore.Qt.UpArrow )
          scene.addLine( QtCore.QLineF( 0, 0, 100, 100 ), pencil )
  
  if ( __name__ == '__main__' ):
      app = QtGui.QApplication([])
      f = MyFrame()
      f.show()
      app.exec_()
  </code></pre>
  
  <p>Which draw this window:</p>
  
  <p><a href="https://i.stack.imgur.com/teQcX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/teQcX.png" alt="enter image description here"></a></p>
  
  <p>How to add a arrow to one of the ends of the line as these I draw over the last image with a image editor:</p>
  
  <p><a href="https://i.stack.imgur.com/MKp0m.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MKp0m.png" alt="enter image description here"></a></p>
  
  <p>I found this tutorial for C++ <a href="http://www.codeproject.com/Articles/3274/Drawing-Arrows" rel="nofollow noreferrer">http://www.codeproject.com/Articles/3274/Drawing-Arrows</a> with this pseudocode:</p>
  
  <pre><code>// ARROWSTRUCT
  //
  // Defines the attributes of an arrow.
  typedef struct tARROWSTRUCT {
      int nWidth;     // width (in pixels) of the full base of the arrowhead
      float fTheta;   // angle (in radians) at the arrow tip between the two
                      //  sides of the arrowhead
      bool bFill;     // flag indicating whether or not the arrowhead should be
                      //  filled
  } ARROWSTRUCT;
  
  // ArrowTo()
  //
  // Draws an arrow, using the current pen and brush, from the current position
  //  to the passed point using the attributes defined in the ARROWSTRUCT.
  void ArrowTo(HDC hDC, int x, int y, ARROWSTRUCT *pArrow);
  void ArrowTo(HDC hDC, const POINT *lpTo, ARROWSTRUCT *pArrow);
  </code></pre>
  
  <blockquote>
    <p>Simply fill an ARROWSTRUCT with the desired attributes, make sure the current DC position is correct (MoveTo(), etc.), and call one of the two ArrowTo() functions. The size parameters (nWidth and fTheta) are defined as follows:</p>
    
    <h3>Technique</h3>
    
    <p>This goes back to high-school algebra and trigonometry. The ArrowTo() function first builds a vector of the full line. Then it calculates the points for the sides of the arrowhead based on the nWidth and fTheta attributes you pass. Badda-boom-badda-bing, you got your arrowhead.</p>
    
    <p>Here's some pseudo-pseudocode:</p>
  </blockquote>
  
  <pre><code>lineVector = toPoint - fromPoint
  lineLength = length of lineVector
  
  // calculate point at base of arrowhead
  tPointOnLine = nWidth / (2 * (tanf(fTheta) / 2) * lineLength);
  pointOnLine = toPoint + -tPointOnLine * lineVector
  
  // calculate left and right points of arrowhead
  normalVector = (-lineVector.y, lineVector.x)
  tNormal = nWidth / (2 * lineLength)
  leftPoint = pointOnLine + tNormal * normalVector
  rightPoint = pointOnLine + -tNormal * normalVector
  </code></pre>
  
  <p>Moreover I could also find this other question <a href="https://stackoverflow.com/questions/35316781/drawing-a-polygon-in-pyqt">Drawing a polygon in PyQt</a> but it is for qt5. Therefore is it a better way to draw the arrows with polygons in pyqt4?</p>