简体   繁体   English

QWidget背景色不能完全覆盖QWidget

[英]QWidget background color does not fully cover the QWidget

Using Qt Creator, I have set a QWidget's background property to black. 使用Qt Creator,我将QWidget的background属性设置为black。 However, some parts of the QWidget, more specifically, between QFrames/QGroupBoxes are still in its system's default color. 但是,QWidget的某些部分(尤其是QFrames / QGroupBoxes之间的部分)仍处于其系统的默认颜色。

Now, I thought that the QFrames and QGroupBoxes need to have its background property set to black too, but it did not work. 现在,我认为QFrames和QGroupBoxes也需要将其background属性设置为black,但是它不起作用。 I have also tried setting the border-color to black, but it does not work, since by default borders, margins are set to 0. 我也尝试将border-color设置为black,但是它不起作用,因为默认情况下,borders的边距设置为0。

QWidget { background: black; }

Any advice on this issue? 关于这个问题有什么建议吗?

EDIT 编辑

The QWidgets are placed in QMdiArea. QWidget放置在QMdiArea中。 However, if I make it a QWindow, it works. 但是,如果我将其设为QWindow,则可以正常工作。 However, I want the QWidgets to be in the QMdiArea. 但是,我希望QWidgets位于QMdiArea中。 Also, if I just show the QWidgets as it is, the spaces that I have mentioned above are transparent. 另外,如果我仅按原样显示QWidget,则上面提到的空间是透明的。

It sounds like you have some widgets within another widget, and are setting the contained widgets to be black, but then the space between them is not black. 听起来您在另一个小部件中有一些小部件,并且将包含的小部件设置为黑色,但是它们之间的空间不是黑色。 If that is the case, it is likely because you have a layout in the containing widget, which allocates space between each contained widget. 如果是这样,可能是因为您在包含的小部件中有一个布局,该布局在每个包含的小部件之间分配了空间。 The empty space between widgets will be drawn with the containing widget's background color. 小部件之间的空白区域将使用包含的小部件的背景色绘制。

Found out the solution. 找到解决方案。 It seems that you need to set the background color at the QMdiSubWindow, not at QWidget. 似乎您需要在QMdiSubWindow而不是QWidget上设置背景色。 Don't know why, but it seems logical. 不知道为什么,但是似乎合乎逻辑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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