2

I'm trying to change the default QGIS scale bar from meters to feet. From the API documentation it looks like I should be able to use the QgsComposerScaleBar.applyDefaultSize() function.

I thought this would work

scalebar = QgsComposerScaleBar(c)
scalebar.setComposerMap(composerMap)
feet = QgsComposerScaleBar.ScaleBarUnits.Feet
scalebar.applyDefaultSize(feet)
c.addItem(scalebar)

but I get the error

Object::disconnect: No such signal QObject::extentChanged()

Any ideas on how to do this, or what this error means?

I'm using QGIS 2.6.1-Brighton and the CRS for my dataset is EPSG:26917 - NAD83 / UTM zone 17N.

1
  • Have you tried: scalebar.applyDefaultSize(QgsComposerScaleBar.Feet) orscalebar.setUnits(QgsComposerScaleBar.Feet)? Commented Feb 11, 2015 at 15:16

2 Answers 2

2

If I got you right, you can define the units of the QGIS scale bar this way:

  • Using the GUI:

    Go to Settings->Options->Map Tools->Measure Tool and set Preferred measurement units to Feet.

  • Programmatically: Open a QGIS console and copy this:

    from PyQt4.QtCore import QSettings    
    QSettings().setValue("Qgis/measure/displayunits","feet")
    
0

Thanks for the help @gcarrillo!

As far as I can tell QSettings().setValue("Qgis/measure/displayunits","feet") had no effect, but scalebar.applyDefaultSize(QgsComposerScaleBar.Feet) did the trick.

For prosperity, here's a working example of changing the scale bar to miles.

scalebar = QgsComposerScaleBar(c)
scalebar.setComposerMap(composerMap)
scalebar.applyDefaultSize(QgsComposerScaleBar.Feet)
scalebar.setUnitLabeling("mile")
scalebar.setNumMapUnitsPerScaleBarUnit(5280.0)
scalebar.setNumSegmentsLeft(0)
scalebar.setNumSegments(4)
scalebar.setNumUnitsPerSegment(0.25*5280.0)
c.addItem(scalebar)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.