0

Adding x number of extra tabs to the central widget is simple just by using this tabWidget.addTab():

self.tab = QtWidgets.QWidget()

for i in range(5):
    self.tabWidget.addTab(QtWidgets.QWidget(), "tab" + str(i))

However, QTableWidget doesn't seem to have such a feature and instead requires the name of the QWidget every time. This means that I'd have to manually create each tab object for numbers in my range:

self.tab_1 = QtWidgets.QWidget()
self.tab_2 = QtWidgets.QWidget()
...

... before I can use them in the tableWidget. Where the first line puts the table in tab_1 or the second line which duplicates the table in all tabs.

self.tableWidget = QtWidgets.QTableWidget(self.tab_1)
#self.tableWidget = QtWidgets.QTableWidget(self.tabWidget)

So I'd like some way of creating dynamic variables in my for loop (which I hear is a big no-no in Python) or some way of creating different reference-able tables in each of the tabs.

Prof
  • 657
  • 1
  • 14
  • 24
  • @three_pineapples I promise I did try that before I posted and only now did it work for me. Now that's done, could I trouble you with one more question? If I have a tab called "Tab1" defined in setupUI class, how do I reference a table in Tab1 from another function? – Prof Nov 08 '15 at 21:17
  • @three_pineapples I have seen the `QTabWidget.widget(index)` but I am unsure how to use it as I keep getting: `TypeError: QTabWidget.widget(int): first argument of unbound method must have type 'QTabWidget'` – Prof Nov 08 '15 at 21:31
  • You need to call the method on an instance of a `QTabWidget`, not directly from the class. So do something like `self.tabWidget.widget(0)` – three_pineapples Nov 08 '15 at 22:04
  • @three_pineapples Ended up getting it to work using `self.tablelist[0]` where tablelist is a `QTableWidget` item – Prof Nov 08 '15 at 22:16

0 Answers0