title: QGraphicsLineItem::paint() artifacts
body: <p>I have my own class which inherits from <code>QGraphicsLineItem</code> and overrides the <code>paint()</code> method to draw a thick line with an arrow head:</p>
  
  <pre><code>void MyGraphicsItem::paint( QPainter* aPainter,
                              const QStyleOptionGraphicsItem* aOption,
                              QWidget* aWidget /*= nullptr*/ )
  {
      Q_UNUSED( aOption );
      Q_UNUSED( aWidget );
  
      QLineF cLine = line();
  
      aPainter-&gt;setPen( QPen( Qt::black, 6, Qt::SolidLine ) );
      aPainter-&gt;drawLine( cLine );
  
      qreal lineAngle = cLine.angle();
  
      const qreal radius = 2.0;
      QLineF head1 = cLine;
      head1.setAngle(lineAngle+32);
      head1.setLength( 12 );
      QLineF head2 = cLine;
      head2.setAngle(lineAngle-32);
      head2.setLength( 12 );
  
      aPainter-&gt;drawLine( head1 );
      aPainter-&gt;drawLine( head2 );
  
      aPainter-&gt;setPen( QPen( Qt::yellow, 2, Qt::SolidLine ) );
  
      aPainter-&gt;drawLine( cLine );
  
      aPainter-&gt;drawLine( head1 );
      aPainter-&gt;drawLine( head2 );
  }
  </code></pre>
  
  <p>This seems to cause rendering artifacts when I draw the item around the scene. From what I can tell its because I've set a thickness on the <code>QPen</code> which makes me believe that I must somehow be drawing outside of the items rectangle?</p>
  
  <p>What is causing my rendering issue and how can I solve it?</p>
  
  <p><img src="https://i.stack.imgur.com/6T7mk.png" alt="enter image description here"></p>
  
  <p>Notice the background not being redrawn in the image - this happens to any other objects in the scene that the arrow is dragged over too.</p>
  
  <p>Edit: I think this is actually my problem:</p>
  
  <p><a href="https://stackoverflow.com/questions/10709694/subclassing-qgraphicsview-and-setting-drawbackground?rq=1">Subclassing QGraphicsView and setting drawBackground</a></p>
  
  <p>Edit again: Seems drawing the background is the problem, but using full view port updates kills performance so I came up with this which seems to keep the CPU usage at 3% rather than pegging out one core to 100% usage.</p>
  
  <pre><code>// This code lives in the QGraphicsScene constructor, doesn't have to be there though since QGraphicsScene::setBackgroundBrush is public.
  int gridSizeX = 25;
  int gridSizeY = 20;
  QImage singleGrid( gridSizeX, gridSizeY, QImage::Format_RGB32 );
  singleGrid.fill( Qt::white );
  {
      QPainter painter( &amp;singleGrid );
  
      // Lighter background
      painter.setPen( QPen( QColor( 240, 240, 240 ) ));
  
      qreal midx = gridSizeX / 2;
      qreal midy = gridSizeY / 2;
      painter.drawLine( 0, midy, gridSizeX, midy );
      painter.drawLine( midx, 0, midx, gridSizeY );
  
      // Darker foregound
      painter.setPen( QPen( QColor( 180, 180, 180 ) ));
      painter.drawRect( 0, 0, gridSizeX, gridSizeY );
  
      painter.end();
  }
  QBrush brushBackground( singleGrid );
  setBackgroundBrush( brushBackground );
  </code></pre>
  
  <p>The scene then repeats this brush everywhere resulting in the same grid background effect, it even works as expected when zoomed/scaled. :).</p>