I am making several maps from a template with a PyQGIS script and I am having problems to align the scale bar on them. My code is:

# create scale bar
item = QgsComposerScaleBar(comp)
item.setStyle('Single Box') # Other possibilities are: 'Single Box', 'Double Box', 'Line Ticks Middle', 'Line Ticks Down', 'Line Ticks Up', 'Numeric'

I've found the QgsComposerScaleBar.setAlignment() QGIS API Documentation, but when I introduce 'Right' as a parameter I get a type error message. I am using QGIS 2.6.0

1 Answer 1


The setAlignment() method accepts the enumarator QgsComposerScaleBar::Alignment. So you should change your code as following:


Hope this helps.

  • 2
    Thanks! Yes, that was the solution to the type error, but the scale bar kept not moving. In the end I solved the issue making the item position relative to its size and to the right margin: item_x_position = comp.paperWidth() - 25 - 5*item.segmentMillimeters() item.setItemPosition(item_x_position ,190, 30, 10)
    – fgiron
    Commented Dec 9, 2014 at 9:07

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.