I'm trying to make my widget paint a rectangle with every paintEvent it receives. The rectangles are supposed to increase in size by 1px at a time, filling a square. What I get, however, is only the latest (and largest) rectangle.
void TestClass::paintEvent(QPaintEvent* e){
static int size = 1;
QStylePainter painter(this);
painter.setPen(Qt::blue);
painter.drawRect(QRect(50, 50, size, size));
size++;
}
I don't understand why it would be that way. I expected the painter to just paint on top of what is already there. Instead it seems to delete the previously drawn rectangle, leaving me with a single rectangle at any time. Any ideas?
setAutoFillBackground(true/false)
does not change anything but the color of the background.
To evoke a paintEvent I update()
inside mousePressEvent()
. So my rectangles grow with every click.
Thanks a lot.