问题描述
我有一个透明背景的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浮动时更改背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!