<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[When setting the background of a QScrollArea to transparent, widgets inside lack their frames]]></title><description><![CDATA[<p dir="auto">Hi all,</p>
<p dir="auto">"Is this a bug or a feature?!" – happens both with Qt 5.15.16 and Qt 6.8.2, using the Fusion style.</p>
<p dir="auto">When I put a <code>QScrollArea</code> inside a <code>QGroupBox</code>, the background is painted using a slightly lighter color than the group box's:<br />
<img src="https://ddgobkiprc33d.cloudfront.net/686f501c-4382-4361-a24b-78eea239e486.png" alt="1.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">When I try to get id of this by explicitly setting the background to transparent, the different color is gone – but the widgets inside have their frames removed:<br />
<img src="https://ddgobkiprc33d.cloudfront.net/b3b581ee-ac6b-4752-8368-b71027e5e927.png" alt="2.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">Cf. this minimal example:</p>
<pre><code>#include &lt;QApplication&gt;
#include &lt;QWidget&gt;
#include &lt;QVBoxLayout&gt;
#include &lt;QGroupBox&gt;
#include &lt;QScrollArea&gt;
#include &lt;QLabel&gt;
#include &lt;QPushButton&gt;

class Demo : public QWidget
{
public:
    Demo() {
        QVBoxLayout *layout;
        layout = new QVBoxLayout(this);
        auto *box = new QGroupBox(tr("Some Box"));
        layout-&gt;addWidget(box);

        layout = new QVBoxLayout(box);
        auto *scroll = new QScrollArea;
        scroll-&gt;setFrameShape(QFrame::NoFrame);
        layout-&gt;addWidget(scroll);

        // Uncomment to see the frames being gone
        //QPalette palette;
        //palette.setColor(QPalette::Window, Qt::transparent);
        //scroll-&gt;setPalette(palette);

        auto *widget = new QWidget;
        layout = new QVBoxLayout(widget);
        layout-&gt;addWidget(new QLabel(tr("Some Label")));
        layout-&gt;addWidget(new QPushButton(tr("Some Button")));

        scroll-&gt;setWidget(widget);
    }
};

int main(int argc, char *argv[]) {
    QApplication app(argc, argv);
    Demo demo;
    demo.show();
    return app.exec();
}
</code></pre>
<p dir="auto">What's going on here?! How do I get rid of that different color without losing the frames?</p>
]]></description><link>https://forum.qt.io/topic/161488/when-setting-the-background-of-a-qscrollarea-to-transparent-widgets-inside-lack-their-frames</link><generator>RSS for Node</generator><lastBuildDate>Sun, 12 Jul 2026 21:02:42 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/161488.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 22 Mar 2025 13:53:50 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to When setting the background of a QScrollArea to transparent, widgets inside lack their frames on Tue, 25 Mar 2025 21:46:53 GMT]]></title><description><![CDATA[<p dir="auto">Another update to this:</p>
<p dir="auto">One can prevent this by setting <code>setAutoFillBackground(false)</code>, both for the scroll area's <code>viewport()</code> and the scroll widget set, after it has been set.</p>
]]></description><link>https://forum.qt.io/post/823249</link><guid isPermaLink="true">https://forum.qt.io/post/823249</guid><dc:creator><![CDATA[l3u_]]></dc:creator><pubDate>Tue, 25 Mar 2025 21:46:53 GMT</pubDate></item><item><title><![CDATA[Reply to When setting the background of a QScrollArea to transparent, widgets inside lack their frames on Sat, 22 Mar 2025 16:44:02 GMT]]></title><description><![CDATA[<p dir="auto">Well, at least, when setting the <code>QPalette::Window</code> color, the background of the <code>QScrollArea</code> is painted using this very color – so I suppose it's the correct value.</p>
<p dir="auto">However, this seems to only affect Fusion. When e.g. using KDE's Breeze, the widgets inside are not affected in the same way. So I suppose I have to use the workaround I found (setting the style's default palette for all widgets inside).</p>
]]></description><link>https://forum.qt.io/post/823045</link><guid isPermaLink="true">https://forum.qt.io/post/823045</guid><dc:creator><![CDATA[l3u_]]></dc:creator><pubDate>Sat, 22 Mar 2025 16:44:02 GMT</pubDate></item><item><title><![CDATA[Reply to When setting the background of a QScrollArea to transparent, widgets inside lack their frames on Sat, 22 Mar 2025 15:31:38 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/l3u_">@<bdi>l3u_</bdi></a></p>
<p dir="auto">Have you checked if <code>QPalette::Window</code> role is the correct role for your groupbox background?<br />
Maybe <code>Midlight</code> or <code>Light</code> is used there and you only see the effect at first because you wiped the whole palette config for your <code>QScrollArea</code>?</p>
]]></description><link>https://forum.qt.io/post/823044</link><guid isPermaLink="true">https://forum.qt.io/post/823044</guid><dc:creator><![CDATA[Pl45m4]]></dc:creator><pubDate>Sat, 22 Mar 2025 15:31:38 GMT</pubDate></item><item><title><![CDATA[Reply to When setting the background of a QScrollArea to transparent, widgets inside lack their frames on Sat, 22 Mar 2025 15:27:19 GMT]]></title><description><![CDATA[<blockquote>
<p dir="auto">You construct an empty palette here and only set the <code>QPalette::Window</code> role... other roles are undefined.<br />
Specifying the role that is used for the button might solve this.</p>
</blockquote>
<p dir="auto">Using the scroll area's palette has the very same effect:</p>
<pre><code>auto palette = scroll-&gt;palette();
palette.setColor(QPalette::Window, Qt::transparent);
scroll-&gt;setPalette(palette);
</code></pre>
]]></description><link>https://forum.qt.io/post/823043</link><guid isPermaLink="true">https://forum.qt.io/post/823043</guid><dc:creator><![CDATA[l3u_]]></dc:creator><pubDate>Sat, 22 Mar 2025 15:27:19 GMT</pubDate></item><item><title><![CDATA[Reply to When setting the background of a QScrollArea to transparent, widgets inside lack their frames on Sat, 22 Mar 2025 15:24:04 GMT]]></title><description><![CDATA[<p dir="auto">Yeah, I read the docs … "QPalette::Window: 10 A general background color" … This is really weird …</p>
<p dir="auto">However, one can work around this by setting the background (i.e. <code>QPalette::Window</code>) color to <code>Qt::transparent</code> and then set the <code>style()-&gt;standardPalette()</code> for all widgets inside tol get the original look back.</p>
]]></description><link>https://forum.qt.io/post/823042</link><guid isPermaLink="true">https://forum.qt.io/post/823042</guid><dc:creator><![CDATA[l3u_]]></dc:creator><pubDate>Sat, 22 Mar 2025 15:24:04 GMT</pubDate></item><item><title><![CDATA[Reply to When setting the background of a QScrollArea to transparent, widgets inside lack their frames on Sat, 22 Mar 2025 15:26:37 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/l3u_">@<bdi>l3u_</bdi></a></p>
<p dir="auto">See:</p>
<ul>
<li><a href="https://doc.qt.io/qt-6/qpalette.html#ColorRole-enum" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-6/qpalette.html#ColorRole-enum</a></li>
</ul>
<p dir="auto">There is a limited amount of colors and settings in <code>QPalette</code>, so some controls/areas/widgets share the same role and therefore color.<br />
The lighter color for group box also has to do with this.</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/l3u_">@<bdi>l3u_</bdi></a> said in <a href="/post/823037">When setting the background of a QScrollArea to transparent, widgets inside lack their frames</a>:</p>
<blockquote>
<pre><code>QPalette palette;
palette.setColor(QPalette::Window, Qt::transparent);
scroll-&gt;setPalette(palette);
</code></pre>
</blockquote>
<p dir="auto">You construct an empty palette here and only set the <code>QPalette::Window</code> role... other roles are undefined.<br />
Specifying the role that is used for the button might solve this.</p>
<p dir="auto">Like</p>
<pre><code>auto scrollPalette = scroll-&gt;palette();
scrollPalette.setColor(QPalette::Window, Qt::transparent);
scroll-&gt;setPalette(scrollPalette);
</code></pre>
]]></description><link>https://forum.qt.io/post/823041</link><guid isPermaLink="true">https://forum.qt.io/post/823041</guid><dc:creator><![CDATA[Pl45m4]]></dc:creator><pubDate>Sat, 22 Mar 2025 15:26:37 GMT</pubDate></item><item><title><![CDATA[Reply to When setting the background of a QScrollArea to transparent, widgets inside lack their frames on Sat, 22 Mar 2025 15:07:37 GMT]]></title><description><![CDATA[<p dir="auto">Why would the <code>QPalette::Window</code> ColorRole be used for a border?! Also, the background color of the <code>QGroupBox</code> is very different from the border color of the <code>QPushButton</code> …</p>
]]></description><link>https://forum.qt.io/post/823039</link><guid isPermaLink="true">https://forum.qt.io/post/823039</guid><dc:creator><![CDATA[l3u_]]></dc:creator><pubDate>Sat, 22 Mar 2025 15:07:37 GMT</pubDate></item><item><title><![CDATA[Reply to When setting the background of a QScrollArea to transparent, widgets inside lack their frames on Sat, 22 Mar 2025 14:48:45 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/l3u_">@<bdi>l3u_</bdi></a> said in <a href="/post/823037">When setting the background of a QScrollArea to transparent, widgets inside lack their frames</a>:</p>
<blockquote>
<p dir="auto">What's going on here?!</p>
</blockquote>
<p dir="auto">I think the same color is used for the border and since you modified the palette it's also applied to the child widgets (ie. the button) of your scroll area.</p>
]]></description><link>https://forum.qt.io/post/823038</link><guid isPermaLink="true">https://forum.qt.io/post/823038</guid><dc:creator><![CDATA[Pl45m4]]></dc:creator><pubDate>Sat, 22 Mar 2025 14:48:45 GMT</pubDate></item></channel></rss>