How can I temporarily store QLayout?
-
"contentWidget" is a widget where contents are rendered. As you can see, initially it has no layout.
This is one of the contents which is rendered in the contentWidget. And it has a layout. (indicated with a red circle)
This layout is applied to contentWidget everytime a content is rendered in contentWidget.My topic is, Every time a content in contentWidget changes, I want to store the content (technically the layout applied to contentWidget which has all widgets in contentWidget as children) temporarily so that it will be just loaded, rather than being created again if I render that content again.
To achieve it, I must detach the layout from contentWidget lest I get an error message below.QLayout: Attempting to add QLayout "" to QWidget "contentWidget", which already has a layout
However, it doesn't work well like I expected.
delete this->contentWidget->layout()->setParent(nullptr);
QWidget *temp = new QWidget(); delete this->contentWidget->layout()->setParent(temp);
Those examples make the program crash.
Why this happens? -
"contentWidget" is a widget where contents are rendered. As you can see, initially it has no layout.
This is one of the contents which is rendered in the contentWidget. And it has a layout. (indicated with a red circle)
This layout is applied to contentWidget everytime a content is rendered in contentWidget.My topic is, Every time a content in contentWidget changes, I want to store the content (technically the layout applied to contentWidget which has all widgets in contentWidget as children) temporarily so that it will be just loaded, rather than being created again if I render that content again.
To achieve it, I must detach the layout from contentWidget lest I get an error message below.QLayout: Attempting to add QLayout "" to QWidget "contentWidget", which already has a layout
However, it doesn't work well like I expected.
delete this->contentWidget->layout()->setParent(nullptr);
QWidget *temp = new QWidget(); delete this->contentWidget->layout()->setParent(temp);
Those examples make the program crash.
Why this happens?@Aaron-Kim Sounds like http://doc.qt.io/qt-5/qstackedwidget.html is what you need.