[Qgis-developer] Python init script

Matthias Kuhn matthias.kuhn at gmx.ch
Thu Jul 10 01:39:03 PDT 2014


Hi,

The dialog you get in the openForm method is a QgsAttributeForm.
As such it is possible to access the method changeAttribute( fieldName, 
value ).

However, this method - as well as the method you are currently using - 
do change the value of the field when you change something else and 
then save the form. And possibly even without changing something else.

Instead, I would use another approach if it's only for representation 
issues:
 * Use field type hidden and somehow insert another read-only field 
which shows the value you want to show.
 * Wait for the PR with the expression fields to be merged
 * Implement a custom widget that is able to discern between a rounded 
representation and an internal more precise value

Best,
Matthias

On Thu 10 Jul 2014 10:18:40 AM CEST, Andreas Neumann wrote:
> Hi Bernhard,
>
> Ah I see. It is a different context. I am using a Python init script
> (the one you can specify in the layer properties dialog in the fields
> tab) that is triggered after the dialog already opened. The user is
> using the info tool and the feature form opens and the python init
> script is triggered.
>
> In your example the context is different. Your script would open the
> featureForm.
>
> But thanks anyway,
> Andreas
>
> Am 2014-07-10 10:09, schrieb Bernhard Ströbl:
>> Hallo Andreas,
>>
>>
>> Am 10.07.2014 09:53, schrieb Andreas Neumann:
>>> Hi Bernhard,
>>>
>>> I am able to change the attribute value in the feature record, but the
>>> attribute dialog does not update the value. Probably because "feature"
>>> is not live-linked but a copy of the record?
>>
>> works for me:
>> myFeature = myLayer.selectedFeatures()[0] # access the feature
>> myFeature[myLayer.fieldNameIndex("fieldxy")] = "blabla" # change value
>> if iface.openFeatureForm(myLayer, myFeature): # show dialog
>>   # change feature values for myFeature in myLayer
>>
>> Bernhard
>
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer


More information about the Qgis-developer mailing list