2012-10-22 42 views
0

我正在處理一個自定義樣式的QMessageBox。在方法擦亮我的自定義將QStyle類()我稱之爲:如何刷新QWidget繪畫緩存?

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); 
} 

這工作得很好,除非我們使用了半透明邊框:半透明的部分變得越來越暗每重繪(例如,當按下「顯示詳情「/」隱藏詳情「多次)。

更新:我剛剛意識到,移動消息框時,「太暗半透明內容」也會移動。因此,我想刷新QWidget繪畫緩存 - 如果這樣的東西存在(後備存儲??)。

回答

1

的解決方案來自SRC/GUI /對話框/ qdialog.cpp在管線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 

如果只設置的Qt :: WA_NoSystemBackground我意識到,沒有背景是畫在所有 - 甚至沒有一個由Qt :: WA_NoSystemBackground觸發!

這是由QWidget :: setAttribute()方法引起的,它在設置Qt :: WA_TranslucentBackground時將Qt :: WA_NoSystemBackground設置爲true。上面的解決方法(它是官方的Qt代碼!!)解決了這個問題。