Geographic Information Systems Asked by GIS_lounge on March 16, 2021
I’m developing a QGIS plugin using QtDesigner and pyqt4.
I have a comboBox of my vector layers and I want to show the table of the selected layer.
I used this code for my comboBox:
def run(self):
"""Run method that performs all the real work"""
allLayers = self.iface.legendInterface().layers()
allLyrNames = [lyr.name() for lyr in allLayers]
self.dlg.updateCombos(allLyrNames)
# show the dialog
self.dlg.show()
# Run the dialog event loop
result = self.dlg.exec_()
# See if OK was pressed
if result:
# Do something useful here - delete the line containing pass and
# substitute with your code.
grdLayerName = self.dlg.getGridLayer()
pass
And these two functions:
def getGridLayer(self):
return(unicode(self.GridLayerCombo.currentText()))
def updateCombos(self, items):
if len(items) > 0:
self.GridLayerCombo.clear()
for item in items:
self.GridLayerCombo.addItem(item)
You can take a look at the bottom part sample from https://webgeodatavore.github.io/pyqgis-samples/gui-group/QgsAttributeTableView.html for a solution (disclosure: I'm the author of the content)
You may also look at https://webgeodatavore.github.io/pyqgis-samples/gui-group/QgsMapLayerComboBox.html for a component to select layers
Both samples are standalone: run them in the QGIS Python console after opening any QGIS project. You will need to change iface
reference while integrating in a plugin.
Answered by ThomasG77 on March 16, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP