I have created a layer filter Expression to get specific results query from my layer and I add these results in a list widget using PyQt.
My Expression and my add to list widget work fine (I print correct ids and I see those ids in list widget).
However, if I want to zoom to a feature using double click signal in the list widget then it zooms to the wrong features (features where my Expression is False). Any idea what I have wrong in my code?
My code:
__init__
self.connect(self.ui.listWidget, SIGNAL("itemDoubleClicked (QListWidgetItem
*)"), self.Zoomt)
My filter:
def myfilter(self):
layer = QgsMapLayerRegistry.instance().mapLayersByName("mylayrt")[0]
request = QgsFeatureRequest().setFilterExpression('"name" =\'{0}\''.format(myname))
for feature in layer.getFeatures(request):
print str(feature.attribute("myid"))
self.ui.listWidget.addItem(str(feature.attribute("myid")))
Result print:
1
42
43
44
45
96
111
304
458
508
579
602
606
646
That is ids are added correctly in the list widget (14 ids).
Zoom button:
def Zoomt(self):
Vl_Gs = QgsMapLayerRegistry.instance().mapLayersByName("mylayer")[0]
Vl_Gs.removeSelection
Vl_Gs.setSelectedFeatures([self.ui.listWidget.currentRow()])
self.mapCanvas.zoomToSelected(Vl_Gs)
Zoom ids (take first 14 from my layer):
0
1
2
3
4
5
6
7
8
9
10
11
12
13
Ids len number is correct but the ids zoom is wrong, why?
Vl_Gs.removeSelection
should beVl_Gs.removeSelection()