Introduction
QWidget is the base class of all user interface objects which means that the same approaches for changing the background color can be used with them too.
Using the Palette
The first example demonstrates how to change the background color using QPalette
首先设置autoFillBackground属性为真
然后定义一个QPalette对象
设置QPalette对象的背景属性(颜色或图片)
最后设置QWidget对象的Palette
m_pMyWidget = new QWidget(this); m_pMyWidget->setGeometry(0,0,300,100); QPalette