首先设置autoFillBackground属性为真
然后定义一个QPalette对象
设置QPalette对象的背景属性(颜色或图片)
最后设置QWidget对象的Palette
实例:
QWidget *widget = new QWidget;
widget->setAutoFillBackground(true);
QPalette palette;
palette.setColor(QPalette::Background, QColor(192,253,123));
//此处的数值,可以在样式表 中先选中你需要的颜色,然后 cope 数值即可。
//palette.setBrush(QPalette::Background, QBrush(QPixmap(":/background.png")));
widget->setPalette(palette);
本文介绍如何使用Qt设置QWidget对象的背景颜色或图片。通过设置autoFillBackground属性为真,并利用QPalette对象定义背景样式。
177

被折叠的 条评论
为什么被折叠?



