[Qgis-developer] Python init script

Andreas Neumann a.neumann at carto.net
Thu Jul 10 00:53:41 PDT 2014

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?

The other bad thing is that there is no way to address widgets by 
objectName. They don't seem to have object names in drag-and-drop mode 
or in the standard feature form mode. So no way to use 
dialog.findChild() or dialog findChildren(). Only if you use qtdesigner 
forms you can set the objectname.

I think that the widgets in the feature form should be addressable by 
objectName in the future. Will open a feature request.


Am 2014-07-10 09:04, schrieb Bernhard Ströbl:
> Hi Andreas,
> I doubt you can access the QLineEdit (though I do not know for sure).
> Why don't you change the attribute data of the feature before opening
> the form (keeping the "real" value in memory and redoing the change if
> the user did not change the value in the form)?
> Bernhard
> Am 09.07.2014 16:09, schrieb Andreas Neumann:
>> Hi,
>> I am trying to do a python init script that executes upon opening a 
>> form
>> (the standard-form, not a custom form).
>> The script should take a value of a feature, round the value (without
>> modifying the data) and display it in the form instead of the 
>> unrounded
>> value.
>> I can get access to the attribute data, but don't know how to access 
>> the
>> QLineEdit to change the value in the form.
>> Here is what I did so far:
>> ---------------------------------------------------------------
>> # -*- coding: utf-8 -*-
>> # Import the PyQt and QGIS librariesfrom qgis.core import *
>> from PyQt4.QtCore import *
>> from PyQt4.QtGui import *
>> from qgis.core import *
>> from qgis.gui import *
>> def featureFormInit(dialog,layer,feature):
>> 	area_rounded = round(feature.attribute("f_area"))
>> 	feature.setAttribute("f_area",area_rounded)
>> ---------------------------------------------------------------
>> The above code works fine so far and I checked by logging the rounded
>> value. How can I now get access to the correct widget and replace the
>> unrounded value with the rounded one?
>> Thanks for any hint,
>> Andreas
> __________ Information from ESET Mail Security, version of virus
> signature database 10073 (20140710) __________
> The message was checked by ESET Mail Security.
> http://www.eset.com
> _______________________________________________
> 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