Important: Please read the Qt Code of Conduct -

How to add dynamically tabs to QTabWidget created by QT Creator

  • I am trying to add dynamically tabs to QTabWidget created by QT Creator. My problem is when I create the interface with QT Creator, there are 2 tabs created by default : Tab 1 and Tab 2. To add tabs, I used the method insertTab.

    To remove Tab 1 and Tab 2, I used the method remove tabs.

    I am searching for a new method that avoids removing tab 1 and tab 2 and put tabs in the corect order.

    I put my code :

        self.tabs = self.findChild(QtGui.QTabWidget, 'tabWidget')
        checked_list = [u'Base Scenario 1991 - 91A', u'Intermediate 1996 - 96A', u'Trend Scenario 2001 - 01T']
        nb_tabs = len(checked_list)
        for i in range(nb_tabs) :
        self.tabs.addTab(QtGui.QWidget(),"All checked scenarios")
    def add_new_tab(self,index,text):
        self.new_tab = QtGui.QWidget()
    def remove_default_tabs(self,nb_tabs):
         # we suppose that in QT Creator we don't change the names of the default tabs (Tab 1 and Tab 2)
        if self.tabs.tabText(nb_tabs) == "Tab 1" :
        if self.tabs.tabText(nb_tabs) == "Tab 2" :

  • Lifetime Qt Champion

    There is
    It will clear the tabwidget but NOT delete the pages.( the widgets)
    There are still in self.ui.NAME
    You can then insert again if its not right order to begin with.

    Im not sure what function u are looking for ?
    Something that could re-arrange the index or ?

  • Hello,

    Thank you mrjj for your answer.

    Finally, I found an easy solution which consists in deleting default tabs (Tab 1 and Tab 2) from QT Creator. It is very easy and simple.

    Thanks again.

  • Lifetime Qt Champion

    I didn't suggest that as i assumed you wanted to keep them :)

Log in to reply