<div dir="ltr"><div>Hi Germán,</div><div><br></div><div>Thank you so much for these suggestions and code snippets.</div><div><br></div><div>I also came across the QgsEditorWidgetSetup - but had no idea how to use it. The Python cookbook did not mention it. The cookbook is really great - but for interactive forms, there is not so much information.<br></div><div><br></div><div>I will try it and report back.</div><div><br></div><div>Thank you very much Germán,</div><div>Andreas<br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, 19 Feb 2023 at 00:59, Germán Carrillo via QGIS-Developer <<a href="mailto:qgis-developer@lists.osgeo.org">qgis-developer@lists.osgeo.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">Hi Andreas, <div><br></div><div><br></div><div>you can modify your Value Relation widget's filter expression using the QgsEditorWidgetSetup class, in this way:</div><div><br></div><div>1) Get the editor widget setup and get a copy of its config dictionary:</div><div><br></div><div>    ews = layer.editorWidgetSetup(3)  # <i>Let's assume your Value Relation widget is set for a field with index 3</i><br>    new_config = ews.config()  # <i>We'll use the current config as a basis to modify only the filter expression</i><br><br></div><div>2) Modify the config dict's filter expression:</div><div><br></div><div>    new_config['FilterExpression'] = 'your new expression'</div><div><br></div><div>3) Apply changes to your layer:</div><div><br>    new_ews = QgsEditorWidgetSetup('ValueRelation', new_config)<br>    layer.setEditorWidgetSetup(3, new_ews)  # <i>Remember that 3 corresponds to the field index</i><br></div><div><br></div><div>And that's it! You should have now a different set of values in the Value Relation widget.</div><div><br></div><div><br></div><div>Regards,</div><div><br></div><div>Germán</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">El lun, 13 feb 2023 a las 5:40, Andreas Neumann via QGIS-Developer (<<a href="mailto:qgis-developer@lists.osgeo.org" target="_blank">qgis-developer@lists.osgeo.org</a>>) escribió:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="font-size:10pt;font-family:Verdana,Geneva,sans-serif">
<p>Hi,</p>
<p>I am looking for a code snippet in PyQGIS: how can I change the filter expression for a value relation widget?</p>
<p>Technically, the widget seems to be a QComboBox. I can get access to the combobox, e.g. to get the current value - but how can I access the QGIS related functionality, like changing programmatically settings of the value relation widget , such as the filter expression? I found the QgsValueRelationFieldFormatter object, but it doesn't allow me to change the filter expression. Any idea how I would change the filter expression using Python?</p>
<p>Thank you for any hints,</p>
<p>Andreas</p>

</div>
_______________________________________________<br>
QGIS-Developer mailing list<br>
<a href="mailto:QGIS-Developer@lists.osgeo.org" target="_blank">QGIS-Developer@lists.osgeo.org</a><br>
List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
</blockquote></div><div><br></div>-- <br><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>-----------<br></div><div>   |\__  <br>(:>__)(<br>   |/    <br>Soluciones Geoinformáticas Libres                            <br><a href="http://geotux.tuxfamily.org/" target="_blank">http://geotux.tuxfamily.org/</a><br><a href="http://twitter.com/GeoTux2" target="_blank">https://twitter.com/GeoTux2</a></div><div><br></div><div><div><a href="http://gis.stackexchange.com/users/4972/germ%c3%a1n-carrillo" target="_blank"><img></a></div></div></div></div></div></div></div></div>
_______________________________________________<br>
QGIS-Developer mailing list<br>
<a href="mailto:QGIS-Developer@lists.osgeo.org" target="_blank">QGIS-Developer@lists.osgeo.org</a><br>
List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><br>--<br>Andreas Neumann<br></div><a href="http://QGIS.ORG" target="_blank">QGIS.ORG</a> board member (treasurer)<br></div></div>