2

I was trying to use the QgsMapToolIdentifyFeature() tool as shown in an answer of StackOverflow, but when executed it gave the error:

'QgisInterface' object has no attribute 'QgsMapToolIdentifyFeature'

I am assuming it was deprecated, in that case how do I call this tool in PyQgis3.4?

Thriskel
  • 355
  • 1
  • 14
  • How are you using QgsMapToolIdentifyFeature()? – Joseph Mar 20 '19 at 13:16
  • @Joseph I am using it as self.iface.QgsMapToolIdentifyFeature(atriVector, f) where atriVector=vectorLayer and f=selectedFeature – Thriskel Mar 20 '19 at 13:28
  • @Taras I saw the post, I understand that QgsMapToolIdentifyFeature is a signal, is it right? I am looking for a way to open the IdentifyFeature tool using the selected feature, but I haven't found the actual tool yet, there are these methods: self.iface.actionIdentify().trigger() , self.iface.openFeatureForm(atriVector, f) , self.iface.showAttributeTable(atriVector) but non of them opens the actual tool used in the qgis interface – Thriskel Mar 20 '19 at 13:37

1 Answers1

2

QgsMapToolIdentifyFeature is not deprecated in QGIS 3

https://qgis.org/api/classQgsMapToolIdentifyFeature.html

self.iface.QgsMapToolIdentifyFeature(atriVector, f) is not correct way,you need create a instance for QgsMapToolIdentifyFeature and set map tool after.

I add a minimal example

from qgis.gui import QgsMapToolIdentifyFeature
from PyQt5.QtGui import QColor

def onFeatureIdentified(feature):
    fid = feature.id()
    print ("feature selected : " + str(fid))

layer = iface.activeLayer()
mc=iface.mapCanvas()
mapTool = QgsMapToolIdentifyFeature(mc)
mapTool.setLayer(layer)
mc.setMapTool(mapTool)
mapTool.featureIdentified.connect(onFeatureIdentified)
Fran Raga
  • 7,838
  • 3
  • 26
  • 47
  • This answers the post question, now @Fran Raga do you have any idea about using the Identify tool that shows selected feature's information table available in the Qgis gui in PyQgis? – Thriskel Mar 21 '19 at 17:32
  • Post a new question please, @Thriskel – Fran Raga Mar 21 '19 at 18:40
  • https://gis.stackexchange.com/questions/316003/updating-identify-tool-every-time-feature-is-selected-with-pyqgis the question is already open – Thriskel Mar 21 '19 at 18:42