title: How to paint in a QMainWindow?
body: <p>I have an extremely strange behaviour of a QPainter. In my 'MainWindow::paintEvent()' it works correctly:</p>
  
  <pre><code>QPainter painter(this);
  qDebug() &lt;&lt; "painter adress in paintEvent: " &lt;&lt; (&amp;painter);
  painter.setBrush(Qt::red);
  painter.drawRect(100, 100, 100, 100);
  </code></pre>
  
  <p>So far, so good. But I actually want to paint using a function of a class I wrote, so my 'paintEvent()' looks like this:</p>
  
  <pre><code>QPainter painter(this);
  qDebug() &lt;&lt; "painter adress in paintEvent: " &lt;&lt; (&amp;painter);
  painter.setBrush(Qt::red);
  painter.drawRect(100, 100, 100, 100);
  instance_of_my_class-&gt;paint(&amp;painter);
  painter.drawRect(150, 150, 100, 100);
  </code></pre>
  
  <p>And the 'paint(QPainter *painter)', which is called above, looks like this:</p>
  
  <pre><code>qDebug() &lt;&lt; "painter adress in paint: " &lt;&lt; painter;
  painter-&gt;setBrush(QColor(0, 0, 80));
  painter-&gt;drawRect(0, 0, 1000, 1000);
  </code></pre>
  
  <p>Obviously, I would now expect to see a dark blue background with one red rectangle (the second one, the first one should be overpainted within 'paint'). However, I see the two red rectangles and in my toolbar all icons have a dark blue background. Furthermore, the output of 'qDebug()' looks as follows:</p>
  
  <pre><code>painter adress in paintEvent:  0xbfd43b54
  painter adress in paint:  0xbfd43b54
  </code></pre>
  
  <p>It definetly is the same QPainter, but within my class it is painting below the icons in my toolbar!?!</p>