Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to temporarily replace the widget of an existing tab?



  • Re: Qtabwidget change widget of existing tab

    For example I have multiple widgets of the same class that I want to switch between, the first widget has been added to the tab using the addTab function, Now I want a new object to appear in this tab and hide the current widget, the question I have linked to says the only way to change the widget of an existing tab is to remove the tab and insert a new one. Although the problem with this is that I dont want to lose the saved contents of the previous widget and want the possibility for making it reappear when I need it again.

    What can be a solution to that? Thanks in advance



  • @sarimcharania
    Before you go any further, are you wedded to a QTabWidget anyway? You want to switch between multiple widgets, showing one at any time. And you want to be able to keep each widget's state when you switch away from it so you can return to it or still get its values. A QStackedWidget seems to fit that bill? Then there isn't an issue about replacing tabs.



  • @sarimcharania Same class, right? If yes, create a model and change the contents, but not the widgets.



  • @JonB much appreciated. That is exactly the solution I was looking for.


Log in to reply