简体   繁体   中英

How to flush the QWidget Painting-Cache?

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 (eg 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:

#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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM