title: QTabWidget not letting me use custom class
body: <p><em>Edits: Phrasing and included a minimum reproducible example</em></p>
  <p>I have a question about how object names work in PyQt5 / how OOP works in PyQt5:</p>
  <h1>Background</h1>
  <p>I'm working on a project which includes a QTabWidget. This QTabWidget adds a new tab each time a '+' tab is clicked:<br>
  Before click:</p>
  <p><img src="https://i.stack.imgur.com/CCFhu.png" alt="Original tabs" /></p>
  <p>After click:</p>
  <p><img src="https://i.stack.imgur.com/80wgD.png" alt="New tab added" /></p>
  <p>When I add the new tab as just a blank widget using <code>insertNewRegionTab()</code>, everything works properly; however, when I instead use a <em>custom class</em> that is a derived class of QtWidgets.QWidget (customTab), the program crashes. I created this class so that each tab would have the same formatting / internal relationships between objects, and that I could just add as many as I needed with the '+' button.</p>
  <p>I think the crashing may be due to name conflicts, e.g. a label called &quot;label1&quot; being created in two tabs simultaneously.</p>
  <h1>Question</h1>
  <p>The problem is that I don't see how name conflicts could be an issue if each customTab is it's own object. I'm wondering if any one knows why I can't implement this customTab class in the desired way.</p>
  <h1>Proposed Solution</h1>
  <p>My thoughts on a solution is to just define class counters and then increment every time a new tab is added so they all have unique names, but this is a bit of work so I wanted to make sure that this is actually what the problem is before I implement it.</p>
  <h1>Code</h1>
  <p>N.B. - The two original tabs using this code will not have names. The one on the left, 'Test 1', has a combo box in it and is in the customTab class. The one on the right, '+', adds a new tab, but a normal QWidget instead of customTab object</p>
  <pre class="lang-py prettyprint-override"><code>from PyQt5 import QtCore, QtGui, QtWidgets
  
  
  class topLevelWindow(QtWidgets.QMainWindow):
      def __init__(self):
          # Function that is used to add tabs
          def insertNewRegionTab(self):
              if self.mainTabWidgetCount == 1 + self.mainTabWidget.currentIndex():
                  
                  # Attempted method 1:
                  tab = QtWidgets.QWidget()  # Want this to be a customTab not a QWidget
                  self.mainTabWidget.insertTab(self.mainTabWidget.currentIndex(),
                                                tab, &quot;Tab &quot; + str(self.mainTabWidgetCount))
  
                  # Attempted method 2:
                  # self.tabInstaces.append(customTab(self.mainTabWidget))
  
                  self.mainTabWidgetCount += 1
  
          super().__init__()
          # Initialization of main window
          self.setObjectName(&quot;MainWindow&quot;)
          self.resize(500, 300)
          self.centralwidget = QtWidgets.QWidget(self)
          self.centralwidget.setObjectName(&quot;centralwidget&quot;)
          self.gridLayout_5 = QtWidgets.QGridLayout(self.centralwidget)
          self.gridLayout_5.setObjectName(&quot;gridLayout_5&quot;)
  
          # Create the main tab widget and set properties
          self.mainTabWidget = QtWidgets.QTabWidget(self.centralwidget)
          self.mainTabWidget.setObjectName(&quot;mainTabWidget&quot;)
          self.mainTabWidget.setCurrentIndex(0)
          self.gridLayout_5.addWidget(self.mainTabWidget, 1, 1, 1, 1)
          self.setCentralWidget(self.centralwidget)
  
          # Insert a tab (of the custom, pre-formatted tab class) into this tab widget
          self.tabInstances = [customTab(self.mainTabWidget)]
          self.mainTabWidgetCount = 2
  
          # Add the tab which creates other tabs to the tan widget
          self.addRegionTab = QtWidgets.QWidget()
          self.addRegionTab.setObjectName(&quot;addRegionTab&quot;)
          self.mainTabWidget.addTab(self.addRegionTab, &quot;&quot;)
  
          # Add functionality: When '+' tab is selected, add a tab
          self.mainTabWidget.currentChanged.connect(lambda: insertNewRegionTab(self))
  
          # Show window
          self.show()
  
  
  class customTab(QtWidgets.QWidget):
      def __init__(self, parent=None):
          # Initializes the object itself and renames it. Add vertical layout to it
          super(customTab, self).__init__()
          self.setObjectName(&quot;tabInstances&quot;)
          self.verticalLayout = QtWidgets.QVBoxLayout(self)
          self.verticalLayout.setObjectName(&quot;verticalLayout&quot;)
  
          self.comboBox1 = QtWidgets.QComboBox(self)
          self.comboBox1.setObjectName(&quot;comboBox1&quot;)
          self.comboBox1.addItem(&quot;&quot;)
          self.comboBox1.addItem(&quot;&quot;)
  
  
          # Add self to parent
          parent.addTab(self, &quot;&quot;)
  
  
  
  
  if __name__ == &quot;__main__&quot;:
      import sys
  
      app = QtWidgets.QApplication(sys.argv)
  
      MainWindow = topLevelWindow()
  
      sys.exit(app.exec_())
  
  </code></pre>