[PyQt] Creating check boxes dynamically inside the listview based on the layers loaded in QGIS
farookrceg at gmail.com
Fri May 1 17:58:26 BST 2015
I have a two list views named "Datacheckerlistview1" and
"Datacheckerlistview2" in my gui. Now i had loaded layers in QGIS. Based on
the number of layers loaded, i want check boxes to be created dynamically
with the layer name inside the "Datacheckerlistview1"..( for ex: if there
are 4 layers loaded, i want 4 check boxes to be created dynamically inside
the Datacheckerlistview1). I had also attached my code below, i don't find
any check boxes inside the list view with the code below. I am new to
Python as well as QGIS. Help would be appreciated.
from PyQt4 import QtGui, uic
FORM_CLASS, _ = uic.loadUiType(os.path.join(
class DataCheckerClassDialog(QtGui.QDialog, FORM_CLASS):
def __init__(self, parent=None):
# Set up the user interface from Designer.
# After setupUI you can access any designer object by doing
# self.<objectname>, and you can use autoconnect slots - see
""" Adds Checkboxes inside the listview dynamically based on the
number of layers loaded in QGIS. """
canvas = qgis.utils.iface.mapCanvas()
allLayers = canvas.layers()
model = QStandardItemModel()
for i in allLayers:
item = QStandardItem('Item %s' % allLayers.name())
check = Qt.checked if randint(0,1) == 1 else Qt.Unchecked
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the PyQt