Friday, 9 March 2018

python - Getting Layer Properties of QGIS on standalone application using PyQGIS API


I am using PyQGIS API for developing the standalone application to load the certain VectorLayers. I used the QgsMapCanvas to load the map and QgsLayerTreeView to show the layer tree view using code below-


    # Layer Tree View
self.layerTreeRoot = QgsProject.instance().layerTreeRoot()
self.layerTreeModel = QgsLayerTreeModel(self.layerTreeRoot)
self.layerTreeView = QgsLayerTreeView()
self.layerTreeView.setModel(self.layerTreeModel)


self.layoutWidgetLayout = QHBoxLayout()
self.layoutWidgetLayout.addWidget(self.layerTreeView)
self.layerWidget.setLayout(self.layoutWidgetLayout)

Now I want to style the layer and change some behaviors of the style using Layer Properties. How can I get that LayerPropertiesWindow by context menu of Layer as below.


enter image description here



Answer



The full Layer Properties window is not part of the PyQGIS API. Basically, it's part of the "app" library within QGIS, which is code which is only available when running the full QGIS desktop application and accordingly cannot be reused from a standalone script.


However, some individual parts of this dialog ARE exposed via the PyQGIS API and can be reused. Specifically the symbology and labeling settings are reusable widgets (e.g. qgis.gui.QgsSingleSymbolRendererWidget). You could manually construct these widgets in your standalone script to partly re-implement the layer properties dialog.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...