Easy to fix, MainWindow is a qwidget.
Set the background color to blue
Mainwindow.setstylesheet ("background-color:blue;");
Set the background image to Bg.png
Mainwindow.setobjectname ("MainWindow");
Mainwindow.setstylesheet ("#mainWindow {Border-image:url (:/image/bg.png);}");
Note here that ObjectName is not optional and will cause all child controls of the widget to have the same background if not used. The reason for not using "background-image" is that "border-image" can be automatically populated.
If you want to restore the default background, you can call
Mainwindow.setstylesheet (0);
:/image/bg.png preceded by a colon stating that it is a resource defined in QRC; by the way, how to add and edit QRC files.
On the project right click on "Add New ..." and then "qt" = "qt Resource file", a random name = "Next" + "Finish", add QRC file complete.
Next add the picture resource, select the QRC file that you just added, "Add Prefix", suggest "Prefix" set to "/"; then "Add Files" to add the picture to the resource file.
Of course, you can also load pictures directly from the disk. Compared to using a picture defined in a resource file, the time overhead is large, but the space overhead is small and more flexible, such as displaying downloaded pictures.
Mainwindow.setobjectname ("MainWindow");
Mainwindow.setstylesheet ("#mainWindow {border-image:url (c:/downloads/myapp/image/bg.png);}");
http://blog.csdn.net/itjobtxq/article/details/9284415
Qt setstylesheet Add a background color/background image (using a non-resource image)