[Qgis-developer] Python init script

Andreas Neumann a.neumann at carto.net
Wed Jul 9 07:09:17 PDT 2014


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


More information about the Qgis-developer mailing list