This is my first time in trying to develop any automation within the QGIS environment.
I am trying to change a user defined project variable – DMA select – programmatically.
The changed project variable is then used to change the parameter in rule based symbologies for 2 layers using the single variable.
I have written a script that can change the project variable on the Python console when I change the variable manually in the script.
project = QgsProject.instance()
QgsExpressionContextUtils.setProjectVariable(project,'DMA_Select','NORTHMEAD')
iface.mapCanvas().refreshAllLayers()
I have also created a form in QT Designer with a dropdown of the possible values for the project variable.
What do I do next to combine this together so that the selected vale from the combo box can change the project variable?
I've searched around the internet and guides/books for this particular solution and have not came up with anything. I can see that we can bind the form/UI to layers but cannot find an example where it is used to change a project or global variable.
I have inserted in the file change_variable.py - between def initGui(self): and def unload(self):
def VariableValue(self):
self.setVariableValue(value)):
project = QgsProject.instance()
QgsExpressionContextUtils.setProjectVariable(project,'DMA_Select', value)
#iface is accessed by self.iface inside the plugin
self.iface.mapCanvas().refreshAllLayers()
and then in the def run(self): section after
#comboBox is the UI objectName
self.dlg.comboBox.currentTextChanged.connect(lambda currentText: setVariableValue(currentText))
When I open QGIS i get the error message
on the plugin load
The plugin loads okay but when run and dropdown is selected I get this error