[PyQt] Creating check boxes dynamically inside the listview based on the layers loaded in QGIS

Florian Bruhin me at the-compiler.org
Sat May 2 10:45:56 BST 2015


Hi,

* Ahamed Farook <farookrceg at gmail.com> [2015-05-01 22:28:26 +0530]:
>     def dynamicCheckBoxes(self):
>         """ 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
>             item.setCheckState(check)
>             item.setCheckable(True)
>             model.appendRow(item)

It seems you create a new QStandardItemModel here, but never use it -
you'd probably have to do something like   yourview.setModel(model)
at some point.

Florian

-- 
http://www.the-compiler.org | me at the-compiler.org (Mail/XMPP)
   GPG: 916E B0C8 FD55 A072 | http://the-compiler.org/pubkey.asc
         I love long mails! | http://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150502/35b46464/attachment.sig>


More information about the PyQt mailing list