Hi Everyone,

I have 2 QWidget classes in my Project by name Widget and TestWidget. In my Widget Class I have the following objects declared-

widget.h
Qt Code:
  1. TestWidget* objTest;
  2. QScrollArea scrollArea;
  3. QStackedWidget stackedWd;
To copy to clipboard, switch view to plain text mode 

and in widget.cpp
Qt Code:
  1. objTest = new TestWidget;
  2.  
  3. scrollArea.setParent(this);
  4. scrollArea.setGeometry(20,20,360,100);
  5.  
  6. scrollArea.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
  7. scrollArea.setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
  8. scrollArea.setWidget(&stackedWd);
  9. //scrollArea.setWidget(objTest);
  10.  
  11. stackedWd.addWidget(objTest);
  12. stackedWd.setCurrentWidget(objTest);
  13. objTest->raise();
  14. objTest->activateWindow();
To copy to clipboard, switch view to plain text mode 

But unfortunately nothing is visible in the QScrollArea. On the contrary if I exclude QStackedWidget then TestWidget appears fine in the ScrollArea along with the scroll, following is the code for it-

widget.cpp
Qt Code:
  1. objTest = new TestWidget;
  2.  
  3. scrollArea.setParent(this);
  4. scrollArea.setGeometry(20,20,360,100);
  5.  
  6. scrollArea.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
  7. scrollArea.setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
  8. scrollArea.setWidget(objTest);
To copy to clipboard, switch view to plain text mode 

I am just not able to understand why the same thing doesn't happen when I use a QStackedWidget as an intermediate. It would be great if someone would guide me regarding this.

For more info TestWidget is a simple QWidget class with just a QLabel in it. The size of TestWidget is 320x240.