Question

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...

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top