I am trying to design a QTabwidget having two tabs in it. The tab should change based on selection from a QComboBox. I have to populate a QTreewidget instance in the two tabs based on the selection from the combo box i.e same tree should be displayed whenever i switch tabs. I tried creating layouts inside tab and added the same Tree to both the layouts. It works for the first time i.e when i switch tabs I can see the same tree in both the tabs.
Qt Code:
  1. if(self.ui.comboReportsNew.currentText()=="Synthesis"):
  2. self.leftLayout = QtWidgets.QVBoxLayout()
  3. self.ui.tab_2.setLayout(self.leftLayout)
  4. self.leftLayout.addWidget(self.ReqTree) //self.ReqTree is the QTreeWidget
  6. elif(self.ui.comboReportsNew.currentText()=="Code Coverage"):
  7. self.rightLayout = QtWidgets.QVBoxLayout()
  8. self.ui.tab.setLayout(self.rightLayout)
  9. self.rightLayout.addWidget(self.ReqTree)
To copy to clipboard, switch view to plain text mode 
Next time i try to do that it gives me warning " Attempting to add Layout to widget which already has a layout". I tried creating logic to check if my tree widget already has layout and if so , delete the old layout and initialize it with new layout but no luck.

Any help will be very appreciated.