I have an extremely strange behaviour of a QPainter. In my 'MainWindow::paintEvent()' it works correctly:
QPainter painter(this);
qDebug() << "painter adress in paintEvent: " << (&painter);
painter.setBrush(Qt::red);
painter.drawRect(100, 100, 100, 100);
So far, so good. But I actually want to paint using a function of a class I wrote, so my 'paintEvent()' looks like this:
QPainter painter(this);
qDebug() << "painter adress in paintEvent: " << (&painter);
painter.setBrush(Qt::red);
painter.drawRect(100, 100, 100, 100);
instance_of_my_class->paint(&painter);
painter.drawRect(150, 150, 100, 100);
And the 'paint(QPainter *painter)', which is called above, looks like this:
qDebug() << "painter adress in paint: " << painter;
painter->setBrush(QColor(0, 0, 80));
painter->drawRect(0, 0, 1000, 1000);
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:
painter adress in paintEvent: 0xbfd43b54
painter adress in paint: 0xbfd43b54
It definetly is the same QPainter, but within my class it is painting below the icons in my toolbar!?!