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??).
The solution comes from src/gui/dialogs/qdialog.cpp in line 268:
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.