【问题标题】:How to flush the QWidget Painting-Cache?如何刷新 QWidget 绘画缓存?
【发布时间】:2012-10-12 04:58:22
【问题描述】:

我正在开发一个自定义样式的 QMessageBox。在我的自定义 QStyle 类中的方法 Polish() 我调用:

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

这很好用,除非我们使用半透明边框:半透明部分在每次重绘时变得越来越暗(例如,当多次按下“显示详细信息”/“隐藏详细信息”时)。

更新:我刚刚意识到,在移动消息框时,“too-dark semi-transparent content”也会移动。因此,我想刷新 QWidget 绘画缓存 - 如果存在类似的东西(后备存储??)。

【问题讨论】:

    标签: qt qt4 qdialog qmessagebox qstyle


    【解决方案1】:

    解决方案来自268行的src/gui/dialogs/qdialog.cpp:

    #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 代码!!)解决了这个问题。

    【讨论】:

      猜你喜欢
      • 2015-08-24
      • 2018-11-07
      • 1970-01-01
      • 1970-01-01
      • 2011-11-06
      • 1970-01-01
      • 2012-12-06
      • 2019-09-25
      • 2018-02-16
      相关资源
      最近更新 更多