2

In my qss style sheet I define a background color

#sw_MainMiddle {
    background: black;
}

Everything fine, but when I place a scroll QScrollArea in the sw_MainMiddle widget, the background color is gone. Obviously there is no chance to assign a background directly to QScrollArea. Below code has no effect:

QScrollArea {
    background: black;
}

According to this question I have used object name selector to re-assign the background color to the scroll area, no effect too:

#myScrollArea {
    background: black;
}

Anything I am doing wrong?

4

1 回答 1

3

我想我找到了解决方案:

QAbstractScrollArea #scrollAreaWidgetContents {
    background-color: black;
}

scrollAreaWidgetContents滚动区域内的小部件在哪里:

在此处输入图像描述

QSS 参考页

QAbstractScrollArea 的所有衍生产品,包括 QTextEdit 和 QAbstractItemView(所有项目视图类),都支持使用背景附件的可滚动背景。将背景附件设置为固定可提供不随视口滚动的背景图像。将背景附件设置为滚动,当滚动条移动时滚动背景图像。

有关示例,请参阅自定义 QAbstractScrollArea 。

所以你不能自定义让我们说 all QAbstractScrollAreas 或 all QScrollAreas,只有包含它们的小部件(例如QTextEdit)。这就是为什么QScrollArea { background-color: black; }不起作用。但是,如果您想自定义包含滚动区域的特定小部件,此解决方案就足够了。

于 2014-10-02T19:06:10.850 回答