0

How do I access a tableWidget, which is inside the tab1 of a tabWidget??

This is what I have done so far...

table = self.ui.tabWidget.widget(0)
table.setRowCount(5) 

And the Error returned:

Traceback (most recent call last):

    table.setRowCount(5) 
AttributeError: 'QWidget' object has no attribute 'setRowCount'

The Traceback is quite clear, but I do not know how to fix it...

codeKiller
  • 5,493
  • 17
  • 60
  • 115

1 Answers1

2

The problem is that self.ui.tabWidget.widget(0) returns the widget of the first tab which is a container for all the widgets on that tab. So you need to go deeper an probably get the layout of the table widget to find your table tableWidget. Also you could do tableTab.findChildren(gui.QTableWidget) and inspect the list this call returns.

But, said that, I think there is a more easy way of getting your QTableWidget if you used Qt-Designer, and is as simple as referring it by its name: self.ui.tableWidget, default name (or just the name you used on Qt-Designer).

Hope it helps.

Alvaro Fuentes
  • 16,937
  • 4
  • 56
  • 68
  • Yes Xndrme, it thought it couldn't be, but yes, it was as simple as you said, seems like it is not important if the widget is inside other widget, you can just refer it as self.ui.tableWidget and it works. Thanks!! – codeKiller Feb 25 '14 at 07:09