[Qgis-developer] How to detect whether there is a scale bar on the canvas (not composer)

Martin Dobias wonder.sk at gmail.com
Thu Aug 18 14:47:19 PDT 2016


Hi Tom

On Thu, Aug 18, 2016 at 7:48 PM, Tom Chadwin <tom.chadwin at nnpa.org.uk> wrote:
> For plot, see title. How do I find out whether a canvas has a scale bar,
> enabled by the user via View > Decorations > Scale Bar > Enable scale bar?
> I've done my usual ineffective search through the API docs, and can't find
> it.

Your search through API docs was effective, there indeed isn't a
dedicated API call for that :-) The information is stored within
project properties and you can read the enabled state like this:

QgsProject.instance().readBoolEntry("ScaleBar", "/Enabled", False)

This will return a tuple (is_enabled, success) where the first value
is the value you are looking for, the second one just tells whether
the reading of the project property was successful.

Hope that helps!

Cheers
Martin


More information about the Qgis-developer mailing list