I'm programmatically opening the Attribute table via Python through a plugin. All of the columns have a default width, but some of the data that I'm using do not fit.

It's not enough to be able to click the column separator to make the column re-size to fit the data as there are several columns and several layers.
Can I, through Python, change this in any way, or is my only option to create my own table in Qt?
PyQt4.QtGuiand iface fromqgis.utils. Fetch the current layer withcl = iface.mapCanvas().currentLayer(). Check that it's the right layer withcl.name(). Open the attribute table withiface.showAttributeTable(cl), which is showing me the attribute table in the map window. Run theat = [d for d in QApplication.instance().topLevelWidgets() if d.objectName() == u'QgsAttributeTableDialog'], which return a list. This list however is empty. What am I doing wrong here? – user28233 Mar 31 '14 at 12:36at = [d for d in QApplication.instance().topLevelWidgets()]i.e., without the condition for attribute tables there are around 90 objects but none are attribute tables. – user28233 Mar 31 '14 at 12:48[d.objectName() for d in QApplication.instance().topLevelWidgets()]? – Matthias Kuhn Mar 31 '14 at 21:44QApplication.instance().allWidgets()to search foru'AttributeTable'With this I could use the 1st code tip I got. I.e., problem solved. – user28233 Apr 01 '14 at 10:01attrTables[0].findChildren(QTableView)[0].resizeColumnsToContents(). Introspection is very helpful. @Matthias I'm unable to use thetopLevelWidgets()to find theAttributeTable. It gives nothing. Perhaps you should include in the updated answer that one should useallWidgets(). – user28233 Apr 01 '14 at 13:33resizeColumnsToContents()as well. Just to know why the other method didn't work for you: Do you show the attribute table as a dockable dialog? – Matthias Kuhn Apr 01 '14 at 14:21topLevelWidgets(). – user28233 Apr 02 '14 at 06:23