QDockWidget浮动时更改背景颜色 [英] QDockWidget change background color when floating

查看:1045
本文介绍了QDockWidget浮动时更改背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个透明背景的QDockWidget,但是我想在浮动时更改背景颜色或背景图像.看起来qt样式表没有一个伪状态来告诉您它们是否处于浮动状态,所以我想知道:这可能吗?

I have a QDockWidget with a transparent background, but I would like to change the background color or background image when it is floating. It doesn't look like the qt style sheets have a pseudo state to tell you whether or not they are floating, so I'd like to know: is this possible to do?

推荐答案

找到了解决方案.在代码中添加以下连接:

Found the solution. Add the following connection in the code:

    connect(knobDock, &QDockWidget::topLevelChanged, [&] (bool isFloating)
    {
        if (isFloating)
        {
            setAttribute(Qt::WA_TranslucentBackground, false);
            setAttribute(Qt::WA_NoSystemBackground, false); 
        }
    });

这将导致停靠浮动时停靠小部件使用样式表中指定的任何背景,但是停靠时它将透明(即显示主窗口背景).

This will cause the dock widgetto use whatever background is specified in the stylesheet when the dock is floating, but it will be transparent (i.e. show the mainwindow background) when it's docked.

这篇关于QDockWidget浮动时更改背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆