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
TestWidget* objTest;
TestWidget* objTest;
QScrollArea scrollArea;
QStackedWidget stackedWd;
To copy to clipboard, switch view to plain text mode
and in widget.cpp
objTest = new TestWidget;
scrollArea.setParent(this);
scrollArea.setGeometry(20,20,360,100);
scrollArea.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
scrollArea.setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
scrollArea.setWidget(&stackedWd);
//scrollArea.setWidget(objTest);
stackedWd.addWidget(objTest);
stackedWd.setCurrentWidget(objTest);
objTest->raise();
objTest->activateWindow();
objTest = new TestWidget;
scrollArea.setParent(this);
scrollArea.setGeometry(20,20,360,100);
scrollArea.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
scrollArea.setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
scrollArea.setWidget(&stackedWd);
//scrollArea.setWidget(objTest);
stackedWd.addWidget(objTest);
stackedWd.setCurrentWidget(objTest);
objTest->raise();
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
objTest = new TestWidget;
scrollArea.setParent(this);
scrollArea.setGeometry(20,20,360,100);
scrollArea.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
scrollArea.setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
scrollArea.setWidget(objTest);
objTest = new TestWidget;
scrollArea.setParent(this);
scrollArea.setGeometry(20,20,360,100);
scrollArea.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
scrollArea.setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
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.
Bookmarks