[QGIS-Developer] pyqgis zoom using list widget

xristosss20 saxri89 at gmail.com
Sun Jan 21 11:44:27 PST 2018


hello i have create a layer filter Expression to get specific results query
from my layer and i add this results in list widget using pyqt.

my Expression and my add to list widget work fine(i take correct ids numbers
in the print and i see that ids in list widget).

but if i want to zoom feature using double click signal in list widget then
i take zoom
in the wrong features(features where my Expression is False).Any idea where
i have wrong in my code and to take wrong features zoom?


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 add correct in 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
14

is len number is correct but the ids zoom is wrong,why?



--
Sent from: http://osgeo-org.1560.x6.nabble.com/QGIS-Developer-f4099106.html


More information about the QGIS-Developer mailing list