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

Create tabs for QTabWidget, but do not display all tabs.



  • I've added tabs to my QTabWidget in the following way ...

    tabs = new QTabWidget;
    tabs->addTab(new Tab1(mywidget), tr("Tab 1"));
    tabs->addTab(new Tab2, tr("Tab 2"));
    

    Tab1 and Tab2 are classes derived from QWidget. I'd like to just create, say Tab2, but not actually display this tab. But somehow have a handle to the tabs I do not add yet so that I can add and remove them at will.

    How would this be done?


  • Moderators

    I'd like to just create, say Tab2, but not actually display this tab.

    Simply QWidget* tab2 = new Tab2().

    But somehow have a handle to the tabs I do not add yet

    The pointer is a"handle".

    so that I can add and remove them at will.

    Just use addTab/removeTab as in your example whenever you need.


Log in to reply