How to flush the QWidget Painting-Cache?

1.7k views Asked by At

I'm working on a custom styled QMessageBox. In my custom QStyle class in method polish() I call:

if( (pDialog = qobject_cast<QDialog*>( pWidget )) != NULL )
{
    pDialog->setWindowFlags( pDialog->windowFlags() | Qt::FramelessWindowHint );
    // Allow QStyle draw widget background
    pDialog->setAttribute( Qt::WA_StyledBackground, true );

    // Set window background transparent
    QPalette oPalette = pDialog->palette();
    oPalette.setBrush( QPalette::Window, QBrush(Qt::transparent) );
    pDialog->setPalette( oPalette );
}

This works fine, unless we use a semi-transparent border: The semi-transparent part gets darker and darker on every repaint (e.g. when pressing "Show Details"/"Hide Details" many times).

UPDATE: I just realized, that when moving the message box the "too-dark semi-transparent content" is moved too. Thus I want to flush the QWidget painting-cache - if something like this exists (backing-store??).

1

There are 1 answers

0
Charly On

The solution comes from src/gui/dialogs/qdialog.cpp in line 268:

#ifdef Q_WS_S60
if (S60->avkonComponentsSupportTransparency) {
    bool noSystemBackground = testAttribute(Qt::WA_NoSystemBackground);
    // also sets WA_NoSystemBackground
    setAttribute(Qt::WA_TranslucentBackground);
    // restore system background attribute
    setAttribute(Qt::WA_NoSystemBackground, noSystemBackground); 
}
#endif

If setting only Qt::WA_NoSystemBackground I realized, that no background is painted at all - even not the one triggered by Qt::WA_NoSystemBackground!

This is caused by QWidget::setAttribute() method, which sets Qt::WA_NoSystemBackground to true, when setting Qt::WA_TranslucentBackground. The workaround from above (it's official Qt code!!) solves this problem.