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?

4
  • Have you seen this thread IdentifyFeature() use via PyQGIS??
    – Taras
    Mar 20, 2019 at 13:15
  • How are you using QgsMapToolIdentifyFeature()?
    – Joseph
    Mar 20, 2019 at 13:16
  • @Joseph I am using it as self.iface.QgsMapToolIdentifyFeature(atriVector, f) where atriVector=vectorLayer and f=selectedFeature
    – Thriskel
    Mar 20, 2019 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, 2019 at 13:37

1 Answer 1

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)
3
  • 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, 2019 at 17:32
  • Post a new question please, @Thriskel
    – Fran Raga
    Mar 21, 2019 at 18:40
  • gis.stackexchange.com/questions/316003/… the question is already open
    – Thriskel
    Mar 21, 2019 at 18:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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