I have a problem related to this question and the script given as the answer. I can add some functionalities to Attribute Table (AT) by the script in the post. But according to the post, I have to open the AT using
showAttributeTable method, because the method returns the reference of the AT created/opened.
Of course, I can get references of all opened ATs using the following line.
tables = [w for w in qApp.allWidgets() if w.objectName() == 'AttributeTable']
Let's say, I want to add a button to all ATs to be opened or sort by a column for a specific layer. Somehow, I think I need to catch "the AT's opening event" or "a widget/child was added to
A pseudo code for a possible solution:
def something_opened(something): if something is an attribute_table and active_layer is foo_bar: do something main_window.addedsomething.connect(something_opened)
Note: @Ben's answer is pretty nice. But, it still requires me to focus on the AT.