2

I'm trying to dock an attribute table on the left hand side of my window, above the Layers panel.

By enabling "Open new attribute tables as docked windows" (under Settings Options > Data Sources > Feature attributes and table and using code I adopted from Displaying QGIS attribute table on the right, I can do something like:

from qgis.PyQt.QtCore import Qt
from qgis.PyQt.QtWidgets import QApplication

# Display the attribute table (by default it appears at the bottom)
iface.showAttributeTable(some_layer)

# Find, and move attribute table to left hand dock widget area 
attrTables = [d for d in QApplication.instance().allWidgets() if d.objectName() == u'AttributeTable']
iface.addDockWidget(Qt.LeftDockWidgetArea, attrTables[0])

However, the attribute table appears underneath the layers panel. How do I get it to appear above it?

1

You can re-add the Layers Panel which would place it below any existing panels:

from qgis.PyQt.QtCore import Qt
from qgis.PyQt.QtWidgets import QApplication
from PyQt4.QtGui import QDockWidget

iface.showAttributeTable(iface.activeLayer())

# Get active Attribute Table
attrTables = [d for d in QApplication.instance().allWidgets() if d.objectName() == u'AttributeTable']
# Get Layers Panel
layersPanel = [x for x in iface.mainWindow().findChildren(QDockWidget) if x.objectName() == 'Layers']

# Add Attribute Table
iface.addDockWidget(Qt.LeftDockWidgetArea, attrTables[0])
# Add (re-add) Layers Panel so that new panel appears below
iface.addDockWidget(Qt.LeftDockWidgetArea, layersPanel[0])

Attribute table above Layers Panel

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.