Load QWidget into QTabWidget

QTabWidget

QTabWidget is one of the very important container class in Qt. The QTabWidget class provides the stack of tabbed widgets. QTabWidget is derived from QWidget class. So it is very easy to stack the QWidget into QTabWidget.

QTabWidget provides various method to stack or remove the widget into QTabWidget.

1. Add the Tab

Adds a tab with the given page and label to the tab widget, and returns the index of the tab in the tab bar.

Syntax:
    int    addTab(QWidget * page, const QString & label)
    int    addTab(QWidget * page, const QIcon & icon, const QString & label)

   
Example:

    Calc *c = new Calc;
    ui->tabMger->addTab(c, "Calculator");

   
   

2. Insert the Tab

Inserts a tab with the given label and page into the tab widget at the specified index, and returns the index of the inserted tab in the tab bar.

Syntax:
    int QTabWidget::insertTab(int index, QWidget * page, const QString & label)
    int QTabWidget::insertTab(int index, QWidget * page, const QIcon & icon, const QString & label)

   
Example:

    Calc *c = new Calc;
    ui->tabMger->addTab(c, "Calculator");
   
    Note *n = new Note;
    ui->tabMger->insertTab(0, n, "Notepad");

   

3. Remove the Tab

Removes the tab at position index from this stack of widgets. The page widget itself is not deleted.

Syntax:
    void QTabWidget::removeTab(int index)
   
Example:

    Calc *c = new Calc;
    ui->tabMger->addTab(c, "Calculator");
   
    Note *n = new Note;
    ui->tabMger->insertTab(0, n, "Notepad");
   
    ui.tabMger->removeTab(1);