<?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[通过QStyle设置背景色]]></title><description><![CDATA[<p dir="auto">在使用QStyle设置背景色的时候，我在函数<br />
<a class="plugin-mentions-user plugin-mentions-a" href="/user/void">@<bdi>void</bdi></a> MyStyle::polish(QPalette&amp; pal)<br />
{<br />
pal.setBrush(QPalette::Window, QColor(71, 99, 128));<br />
}@</p>
<p dir="auto">中通过QPalette::Window来设置背景色，但是这样设置整个应用都是一样的背景色，如果我要修改某一个widget的背景色的时候，我通过<br />
@QPalette pal(palette());<br />
pal.setBrush(QPalette::Background, Qt::lightGray);<br />
setPalette(pal);@</p>
<p dir="auto">来设置某一个widget的背景，但是这样设置就会把这个widget的子widget的背景色也设置为一样的了，有没有方法可以达到<br />
@QWidget* widget= new QWidget();<br />
widget-&gt;setObjectName("widget");<br />
widget-&gt;setStyleSheet("QWidget#widget{background-color:lightGray}");@</p>
<p dir="auto">设置stylesheet中用#指定窗口的效果，但是是通过QStyle来设置。<br />
谢谢！</p>
]]></description><link>https://forum.qt.io/topic/36101/通过qstyle设置背景色</link><generator>RSS for Node</generator><lastBuildDate>Thu, 23 Apr 2026 23:33:11 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/36101.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 02 Jan 2014 01:58:40 GMT</pubDate><ttl>60</ttl></channel></rss>