一,如何给widget设置背景色
方法1:使用调色板
<span style="font-family:Arial;background-color: rgb(255, 255, 255);"></span>
<span style="font-family:Arial;background-color: rgb(255, 255, 255);">1,设置widget属性:</span>
<span style="font-family:Arial;background-color: rgb(255, 255, 255);"> <span style="color:#000000;">setAutoFillBackground</span><span style="color:#000000;">(</span><span style="color:#80800;">true</span><span style="color:#000000;">);</span></span>
<span style="font-family:Arial;background-color: rgb(255, 255, 255);"></span>
<span style="font-family:Arial;background-color: rgb(255, 255, 255);">2:,调色板</span>
<span style="color:#80080;">QPalette</span><span style="color:#c0c0c0;"> </span><span style="color:#000000;">palette</span><span style="color:#000000;">;</span><pre style="margin: 0px; text-indent: 0px; -qt-block-indent: 0;"><span style="color:#000000;">palette</span><span style="color:#000000;">.</span><span style="color:#000000;">setColor</span><span style="color:#000000;">(</span><span style="color:#80080;">QPalette</span><span style="color:#000000;">::</span><span style="color:#80080;">Background</span><span style="color:#000000;">,</span><span style="color:#c0c0c0;"> </span><span style="color:#80080;">QColor</span><span style="color:#000000;">(</span><span style="color:#0080;">231</span><span style="color:#000000;">,</span><span style="color:#c0c0c0;"> </span><span style="color:#0080;">231</span><span style="color:#000000;">,</span><span style="color:#c0c0c0;"> </span><span style="color:#0080;">231</span><span style="color:#000000;">));</span>
3,给widget设置调色板
setPalette(palette);
方法2:重写paintEvent事件函数
1&#x