Hi All,

I want to paint pic to a widget which inside a qscroll area,
but it seems no pic paint out

here is my code :
Qt Code:
  1. class Widget2 : public QWidget{
  2. public:
  3. Widget2(QWidget *parent) { }
  4. protected:
  5. void paintEvent(QPaintEvent*)
  6. {
  7. QPainter realPainter(this);
  8. realPainter.drawPixmap(0,0,QPixmap("./01.png"));
  9. }
  10. };
  11.  
  12.  
  13.  
  14. class Widget : public QScrollArea{
  15. public:
  16. Widget(QWidget *parent=0)
  17. {
  18. w_ = new QWidget(this);
  19. w_->resize(3000,3000);
  20. setWidget(w_);
  21. }
  22. protected:
  23. void paintEvent(QPaintEvent*)
  24. {
  25. QPainter realPainter(w_);
  26. realPainter.drawPixmap(0,0,QPixmap("./01.png"));
  27. }
  28. private:
  29. QWidget *w_;
  30. };
  31.  
  32. int main(int argc ,char *argv[])
  33. {
  34. QApplication app(argc,argv);
  35. Widget w;
  36. w.show(); //the picture not paint out!!!
  37. ////////////////////////////
  38. //the code blow works ,I was wondering why?:confused:
  39. //Widget2 w;
  40. //w.show(); //the picture not paint out!!!
  41. /////////////////////////
  42.  
  43. app.exec();
  44.  
  45.  
  46. }
To copy to clipboard, switch view to plain text mode 

Any ideas about it ?
Thanks advance for your help
Best regards,
hb