I'm trying to set the background image to my top-level widget and it's not working as expected. Am I doing something wrong here or is it just that you can't set a background image to the top level widget?

This is a (very) small example where my issue is clear; I have a QWidget (StyleTest) in whose constructor I try to set its stylesheet. It does nothing.
I also instantiate another QWidget* (for testing) and I set the very same styleSheet to it. THAT ONE displays perfectly.

What am I doing wrong here?

main.cpp
Qt Code:
  1. #include "styletest.h"
  2. #include <QtGui/QApplication>
  3.  
  4. int main(int argc, char *argv[])
  5. {
  6. QApplication a(argc, argv);
  7. StyleTest w;
  8. w.show();
  9. return a.exec();
  10. }
To copy to clipboard, switch view to plain text mode 

.h
Qt Code:
  1. #ifndef STYLETEST_H
  2. #define STYLETEST_H
  3.  
  4. #include <QtGui/QMainWindow>
  5. #include "qwidget.h"
  6. #include "ui_styletest.h"
  7.  
  8. class StyleTest : public QWidget
  9. {
  10. Q_OBJECT
  11.  
  12. public:
  13. StyleTest(QWidget *parent = 0, Qt::WFlags flags = 0);
  14. ~StyleTest();
  15.  
  16. private:
  17. Ui::StyleTestClass ui;
  18. };
  19.  
  20. #endif // STYLETEST_H
To copy to clipboard, switch view to plain text mode 

.cpp
Qt Code:
  1. #include "styletest.h"
  2.  
  3. StyleTest::StyleTest(QWidget *parent, Qt::WFlags flags)
  4. : QWidget(parent, flags)
  5. {
  6. QString style = " QWidget { background: url(./picture.png); } ";
  7. setStyleSheet(style);
  8.  
  9. QWidget * w = new QWidget();
  10. w->setStyleSheet(style);
  11. w->show();
  12. }
  13.  
  14. StyleTest::~StyleTest()
  15. {
  16.  
  17. }
To copy to clipboard, switch view to plain text mode 


example.jpg


as a side note background-image has the same output/result.

Thanks for your help.