Question

I'd like to know what happens exactly when I call a QWidget's update() method.
Here is the documentation:

http://doc.qt.digia.com/4.5/qwidget.html#update

This function does not cause an immediate repaint; instead it schedules a paint event for processing when Qt returns to the main event loop. This permits Qt to optimize for more speed and less flicker than a call to repaint() does.

I see from the Qt source code that a QUpdateLaterEvent is created and post with type QEvent::UpdateLater

In this part of the documentation http://doc.qt.digia.com/4.5/qevent.html

QEvent::UpdateLater: The widget should be queued to be repainted at a later time.

What does 'later time' mean?
Are my all emited queued signals and the events in the event queue processed before the paint?

Thanks,
Gabor

Was it helpful?

Solution

After checking QWidget::update() source code I've found it calls this method in src/gui/kernel/qwidget.cpp:9544 :

void QWidget::update(const QRect &rect)
{
    if (!isVisible() || !updatesEnabled() || rect.isEmpty())
        return;

    if (testAttribute(Qt::WA_WState_InPaintEvent)) {
        QApplication::postEvent(this, new QUpdateLaterEvent(rect));
        return;
    }

    if (hasBackingStoreSupport()) {
        QTLWExtra *tlwExtra = window()->d_func()->maybeTopData();
        if (tlwExtra && !tlwExtra->inTopLevelResize && tlwExtra->backingStore)
            tlwExtra->backingStore->markDirty(rect, this);
    } else {
        d_func()->repaint_sys(rect);
    }
}

As you can see the QUpdateLaterEvent is only posted if the update() is already called from inside a paintEvent() method.

You can also check QWidget::repaint(const QRect &rect) source on line 9456 - it lacks testAttribute(Qt::WA_WState_InPaintEvent) check.

EDIT

The QUpdateLaterEvent is posted as a Qt::NormalEventPriority event, so it gets processed after all other normal priority events (see src/corelib/kernel/qcoreapplication.cpp:971 and :1003). You might also want to look into compressEvent code, I haven't checked that.

So to finally answer the question: the QUpdateLaterEvent is processed after other high and normal priority events that were in queue before it was posted.

OTHER TIPS

Behavior is not documented == not guaranteed to stay the same between Qt versions. You shouldn't write code which depends on the ordering of paint events relative to other events.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top