hi
In the following program the stylesheet works for Widget class only when i comment the Q_OBJECT macro.

Qt Code:
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3.  
  4. #include <QtGui>
  5.  
  6. class Widget:public QWidget
  7. {
  8. Q_OBJECT//if this line is commented the setStyleSheet works.
  9.  
  10. public:
  11. Widget(QWidget *parent=0);
  12. };
  13.  
  14. class MainWindow : public QMainWindow
  15. {
  16. Q_OBJECT
  17.  
  18. public:
  19. MainWindow(QWidget *parent = 0);
  20.  
  21. private:
  22. Widget *widget;
  23. };
  24.  
  25. #endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode 

mainwindow.cpp file
Qt Code:
  1. #include "mainwindow.h"
  2.  
  3. Widget::Widget(QWidget *parent) :QWidget(parent)
  4. {
  5. }
  6.  
  7. MainWindow::MainWindow(QWidget *parent)
  8. : QMainWindow(parent)
  9. {
  10. widget = new Widget();
  11. widget->setStyleSheet("background-color:red");
  12. setCentralWidget(widget);
  13. }
To copy to clipboard, switch view to plain text mode 

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

how to set the stylesheet of the Widget Class.