-
When the current application runs, a window appears which uses a QVBoxLayout. This layout includes two sub layouts. Using a menu or using a button in one of layout, I would like to change the view. The first layout need not change, but the second layout which is a QGridLayout need to change.
I tried the followings.- I tried to remove the layout and add a new layout. I could not find the correct way to do this.
- I tried closing the window, deleting the view, and then re-constructing view with the change I need. It works sometimes but sometimes it crashes with segmentation fault.
What is the correct way to change the view in Qt6? In Qt Creator, the view changes when Edit, Debug are selected in the side-bar. I would like to do similar thing.
-
@kimjohn
Hello and welcome.It is hard to comment without your attempted code. However if you really want to change from one layout to another the correct way is to remove the existing layout from the widget it is on and then set the new layout on that widget. You would then need to move any widgets on the original layout to the new layout if you wish to retain them.
However. I do not know what exactly you have in mind by " In Qt Creator, the view changes when Edit, Debug are selected in the side-bar.". But if you want to change between two quite different layouts/views with their own widgets: rather than changing the layout, it is more usual to create a QStackedWidget. That allows you to design two quite different widgets, with their own layouts and their own sub-widgets on those layouts, and to swap between which one of the two is shown to the user at any time.
-
Hi and welcome to devnet,
Beside the good recommendation of @JonB, you can also consider the direct use of QStackedLayout in which QStackedWidget is built on.