Is there a way to open attribute table at set the setting to "show selected features" through pyqgis? enter image description here

  • For QGIS 2.x or 3.0? – ndawson May 23 at 23:41
up vote 3 down vote accepted

Yes, you can change the setting (which is available in Settings > Options > Data Sources > Attribute table behaviour) and set this to show selected features whenever the table opens:

from PyQt4.QtCore import QSettings
QSettings().setValue("/Qgis/attributeTableBehaviour", "1")

Attribute table behaviour


Edit:

Using iface.showAttributeTable(iface.activeLayer()) seems to ignore the QSetting and instead show all features as default. An alternative to load the attribute table of the selected layer with the chosen QSetting could be the following:

from PyQt4.QtGui import QAction
iface.mainWindow().findChild( QAction, 'mActionOpenTable' ).trigger()
  • 1
    And to open attribute table with pyqgis see this q/a, gis.stackexchange.com/questions/68332/… – artwork21 May 23 at 12:23
  • Thanks, this works when i right click and opens attribute table, but not if i use iface.showAttributeTable(iface.activeLayer()). Do you know how I can get it to work with that? – Kasper Skjeggestad Oct 11 at 11:03
  • @KasperSkjeggestad - Edited post :) – Joseph Oct 11 at 11:27
  • 1
    That did indeed work, thank you very much! :) – Kasper Skjeggestad Oct 11 at 12:47
  • @KasperSkjeggestad - Most welcome, glad it helped :) – Joseph Oct 11 at 12:48

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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