[QGIS-Developer] pyqgis how set filter legend map content in layer panel

Enzo Cocca enzo.ccc at gmail.com
Mon May 10 00:18:31 PDT 2021


Hi people,

How in pyqgis can I set filter legend on base map content in layer panel?

I load a vector data and I would set filter legend and I would ask you some
suggestions

this my code:

groupName="%s " % (self.dat)
root = QgsProject.instance().layerTreeRoot()
group = root.addGroup(groupName)
group.setExpanded(False)

if settings.SERVER == 'sqlite':
            sqliteDB_path = os.path.join(os.sep, 'pyarchinit_DB_folder',
settings.DATABASE)
            db_file_path = '{}{}'.format(self.HOME, sqliteDB_path)

            uri = QgsDataSourceUri()
            uri.setDatabase(db_file_path)
            uri.setDataSource('', 'pyarchinit_us_view', 'the_geom',
cont_per_string, "ROWID")
            layerUS = QgsVectorLayer(uri.uri(), layer_name_label_us,
'spatialite')

            srs = QgsCoordinateReferenceSystem(self.SRS,
QgsCoordinateReferenceSystem.PostgisCrsId)

            if layerUS.isValid():
                style_path =
'{}{}'.format(self.LAYER_STYLE_PATH_SPATIALITE, 'us_view.qml')
                layerUS.loadNamedStyle(style_path)
                group.insertChildNode(-1, QgsLayerTreeLayer(layerUS))
                QgsProject.instance().addMapLayers([layerUS], False)
  Thanks
E
-- 
Enzo Cocca PhD
in "Science and Technology for Archaeology and Cultural Heritage"

ISMEO
International Association of Mediterranean and Oriental Studies


mail: enzo.ccc at gmail.com
cell: +393495087014
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20210510/b6bd5caa/attachment.html>


More information about the QGIS-Developer mailing list