title: Hiding a QtMainWindow tab in a GUI?
body: <p>I've a GUI (written in PyQt) with three tabs, each a QtGui.QMainWindow class. The whole GUI is defined by a .ui file. That seems to be the main difference between the similar questions on SO (links in next paragraph) where people are looking to hide a QMainWindow object. More specifically, that I'm trying to hide a QMainWindow object that's part of (not the whole) Gui element.</p>
  
  <p>The main window and its tabs look like this:</p>
  
  <p><a href="https://i.stack.imgur.com/xTuwk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xTuwk.png" alt="enter image description here"></a></p>
  
  <p>Depending on a setting in my config file, I want to either leave TEST visible, or hide it from the user. I've checked both the <a href="http://pyqt.sourceforge.net/Docs/PyQt4/qmainwindow.html" rel="nofollow noreferrer">PyQT Docs</a> (ie <code>removeDockWidget()</code>?) and there are two similar SO queries (<a href="https://stackoverflow.com/questions/22538247/pyqt-how-to-hide-qmainwindow">Link One</a> and <a href="https://stackoverflow.com/questions/38739009/pyqt-hide-mainwindow-and-show-qdialog-without-the-taskbar-icon-disappearing?noredirect=1&amp;lq=1">link Two</a>), and a SO Question suggesting <a href="https://stackoverflow.com/questions/11826036/pyside-show-hide-layouts">layouts/setVisible</a>.. </p>
  
  <p>But I can't get it right. If I use <code>.hide()</code> or <code>.setVisible(False)</code> then nothing seems to change. If I set <code>.setVisible(True)</code> then an additional, miniature window appears on startup, with the name of my main class.</p>
  
  <p>The structure of my code is:</p>
  
  <p>My entry/main class:</p>
  
  <pre><code>class Gui:
      def __init__(self):
          # Create the main window GUI and show it
          self.mainWindow= GuiMainWindow(self)
          self.mainWindow.show()
      &lt;...&gt;        
  
  def main():
      app = QtGui.QApplication(sys.argv)  
      myGui = Gui(app)
      sys.exit(app.exec_())
  
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p>GuiMainWindow contain the three tabs:</p>
  
  <pre><code>class GuiMainWindow(QtGui.QMainWindow):
      def __init__(self, appMain):
          QtGui.QMainWindow.__init__(self)
          self.ui = Ui_MainWindow()
          self.ui.setupUi(self)
  
          # Create helper objects to manage main window tabs
          self.daqTab = GuiMainDaqTab(appMain, self)
          self.pwrTab = GuiMainPowerTab(appMain, self)
          self.testTab = GuiMainTestTab(appMain, self)
  
          self.testTab.hideMe()
  </code></pre>
  
  <p>Finally, the TEST tab is what I want to hide/show:</p>
  
  <pre><code>class GuiMainTestTab(QtGui.QMainWindow):
      def __init__(self, appMain, mainWindow):
          super(GuiMainTestTab, self).__init__()
          self.appMain = appMain
          self.mainWindow = mainWindow
          self.ui = mainWindow.ui
          &lt;...&gt;
  
      def hideMe(self):  
          self.close()
      #   self.hide()             # Also tried hide()
      #   self.setVisible(False)  # ..Or setVisible()
  </code></pre>
  
  <p><strong>--- Edit to assist the answer / my match comment to answer below ---</strong></p>
  
  <p>So, the class <code>GuiMainTestTab</code> accesses the contents of the ui file through its member <code>self.ui</code>. Digging through the ui file I found that <code>testTab</code> is its name of the Test tab in the ui file (as opposed to <code>testTab</code> in <code>GuiMainWindow</code>..!). It's attached to a QTabWidget called verticalTabWidget. So to programmatically find Test tab's index, and remove it:</p>
  
  <pre><code>        testIdx = self.ui.verticalTabWidget.indexOf(self.ui.testTab)
          self.ui.verticalTabWidget.removeTab(testIdx)
  </code></pre>