[QGIS-Developer] QGIS attribute form - changing values with Python of disabled widgets
Andreas Neumann
a.neumann at carto.net
Mon Nov 7 07:18:42 PST 2022
Hi Matthias,
Do you mean disabling them with a Python init code and
QgsWidget.setEnabled(False) - right?
Just tried it - and it seems to work ;-)
Thanks for the hint!
Andreas
On 2022-11-07 15:46, Matthias Kuhn wrote:
> Hi Andreas,
>
> How about going the other way around and leaving them as editable in
> the config and disabling the widget via python instead?
>
> Matthias
>
> On Mon, Nov 7, 2022 at 3:42 PM Andreas Neumann via QGIS-Developer
> <qgis-developer at lists.osgeo.org> wrote:
>
>> Hi,
>>
>> I have a QGIS form with a number of widgets that are set to
>> "disabled". I don't want the user to change these values manually, but
>> they should be updated by a Python action "on demand". Hence I set the
>> editable state of these widgets to False.
>>
>> Now I noticed that while I can change values in the widgets with my
>> Python action, the values are not stored when the editable state is
>> set to "False". As soon as I set the editable state to "True", then my
>> Python action works fine and the values are correctly stored.
>>
>> I tried with two approaches:
>>
>> QgsAttributeForm.changeAttribute()
>>
>> and
>>
>> QgsWidget.setValue()
>>
>> Both of these work fine when editable state is enabled, but not, when
>> they are disabled.
>>
>> Is there any way to also change attribute values when the editable
>> state of a widget is set to False?
>>
>> Thanks,
>>
>> Andreas _______________________________________________
>> QGIS-Developer mailing list
>> QGIS-Developer at lists.osgeo.org
>> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>
> [1]
>
> Best of Swiss Enterprise App-Award for QField [1] - Hold the power of
> QGIS in your hand - get it now [2]
Links:
------
[1]
https://www.opengis.ch/2022/11/03/best-of-swiss-enterprise-app-award-for-qfield/
[2] https://qfield.org/get
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20221107/502709b1/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: blocked.gif
Type: image/gif
Size: 118 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20221107/502709b1/attachment.gif>
More information about the QGIS-Developer
mailing list