I use QgsMapToolIdentifyFeature
to trap the featureIdentified
signal, so i can get some information from the identified feature and show it in a panel within my plugin.
here is the code, my problem is the connection between the featureIdentified
signal and my slot is not works:
def onFeatureIdentified(self, ff):
print("feature selected")
def run(self):
f = QgsMapToolIdentifyFeature(self.iface.mapCanvas(), self.iface.activeLayer())
f.featureIdentified.connect(self.onFeatureIdentified)
i don't know that's the problem in my code since it doesn't raise any error.
Answer
This is a simple code for connect your QgsMapToolIdentifyFeature signal.
from qgis.gui import QgsMapToolIdentifyFeature
def onFeatureIdentified(feature):
print "feature selected : "+ str(feature.id())
mapTool = None
mc=iface.mapCanvas()
lyr=iface.activeLayer()
mapTool = QgsMapToolIdentifyFeature(mc)
mapTool.setLayer(lyr)
mc.setMapTool(mapTool)
mapTool.featureIdentified.connect(onFeatureIdentified)
And when click in a feature print the id.
Regards
Tested with QGIS 2.18.14 on W10
UPDATE: Add GIF with QGIS 2.18.13
No comments:
Post a Comment