[Qgis-developer] accessing project properties

Martin Dobias wonder.sk at gmail.com
Wed Oct 5 14:15:49 EDT 2011


On Tue, Oct 4, 2011 at 11:43 AM,  <bernhard.stroebl at jena.de> wrote:
> Hi all,
>
> I got stuck... From within a Python plugin I want to know the current
> project's selection color. I guess I need the corresponding QgsPropertyKeys'
> values.
> Any hints?

Hi Bernhard

you want want to use something like this:

prj = QgsProject.instance()
r = prj.readNumEntry("Gui", "/SelectionColorRedPart", 255)[0]
g = prj.readNumEntry("Gui", "/SelectionColorGreenPart", 255)[0]
b = prj.readNumEntry("Gui", "/SelectionColorBluePart", 0)[0]
a = prj.readNumEntry("Gui", "/SelectionColorAlphaPart", 255)[0]
clr = QColor(r,g,b,a)

The QgsProject class offers a similar interface to QSettings for
access to properties. The example is mostly self-explanatory except
for the "[0]" at the end of the readNumEntry lines. This function in
python returns a tuple: first value is the number, second value is a
boolean whether the conversion to number went fine - for simplicity we
ignore that flag here.

Martin


More information about the Qgis-developer mailing list