When does a Qt widget get a paintEvent?

Viewed 18531

I am wondering in which cases does a widget receive its paint event, and how does it vary with the OS.

Qt documentation for paintEvent says only

A paint event is a request to repaint all or part of a widget. It can happen for one of the following reasons:

repaint() or update() was invoked,

the widget was obscured and has now been uncovered, or

many other reasons.

So far, I've put some traces in the paintEvent,

void Widget::paintEvent(QPaintEvent *e)
{
    static int count = 0;
    qDebug("paintEvent, %d", count++);
}

and this is what I've found out (on Windows 7 at least):

The paintEvent is called when the widget loses/gains focus. The paint event is not called when another widget passes over our widget. I don't know if that's because of Windows 7 compositing. The paintEvent is also called when a minimized window is restored. The paintEvent is called when resizing.

So is the behaviour dependent on the OS?

1 Answers
Related