简体   繁体   English

Mac OS X上的QScrollArea透明背景

[英]QScrollArea transparent background on MacOS X

I have a problem with making contents of QScrollArea to not draw a background. 我在使QScrollArea内容不绘制背景时QScrollArea问题。

So here is the initial picture, when I apply no stylesheet: 所以这是当我不应用样式表时的初始图片: 在此处输入图片说明 You can see, that the contents of scroll area are darker then the overall frame. 您会看到,滚动区域的内容比整个框架的内容更暗。

I have found the stylesheet that I can apply to scroll area, so the background is transparent. 我找到了可以应用于滚动区域的样式表,因此背景是透明的。 Here's the stylesheet I use: 这是我使用的样式表:

QScrollArea { background: transparent; }
QScrollArea > QWidget > QWidget { background: transparent; }

Problem is that when I do that, the scrollbar of scrollarea gets messed up: 问题是当我这样做时,scrollarea的滚动条变得混乱了: 在此处输入图片说明

You see? 你看? The scrollbar is now always visible and is ugly and transparent. 现在,滚动条始终可见,并且丑陋且透明。

How can I make my stylesheet not to affect the scrollbar, while still applying it to the QScrollArea ? 在将样式表应用于QScrollArea同时,如何使样式表不影响滚动条? Or what different stylesheet should I apply instead? 还是我应该应用哪些不同的样式表?

try to set an object name for the scroll area viewport: 尝试为滚动区域视口设置对象名称:

pScrollArea->viewport()->setObjectName("myViewport");

then address it using the hashtag property in the stylesheet (also add the groupbox since the way I see it in your screenshot, your goal is to make them transparent as well): 然后使用样式表中的hashtag属性解决该问题(也要添加分组框,因为我在屏幕截图中看到的方式也是如此,您的目标是也使它们透明):

QScrollArea, #myViewport, QGroupBox { 
  background: transparent;
}

The problem is that QScrollBar is a subclass of QWidget, so just target the viewport with that rule: 问题在于QScrollBar是QWidget的子类,因此只需使用该规则定位视口即可:

pScrollArea->setStyleSheet("QScrollArea { background: transparent; }");
pScrollArea->viewport()->setStyleSheet(".QWidget { background: transparent; }");

Notice the dot before QWidget, so to not target any children of the viewport (ie, any viewport content that's a QWidget subclass). 注意QWidget之前的点,因此不要以视口的任何子对象为目标(即,作为QWidget子类的任何视口内容)。

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

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